Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - dalslandan

Pages: [1]
1
Network / Re: Server and client UDP packet communication
« on: July 26, 2017, 02:08:39 am »
Makes sense, just tested it out and everything works.

Awesome, thank you.  :)

2
Network / Re: Server and client UDP packet communication
« on: July 26, 2017, 02:02:01 am »
Sorry.

There are 6 errors, all corresponding to the same line.

1. expected an identifier
2. variable "packet" is not a type name
3. variable "recipient" is not a type name
4. variable "port" is not a type name
5. C2143 syntax error: missing ';' before .                      (.send is it referring too*)
6. C2059 syntax error: '.'

3
Network / Re: Server and client UDP packet communication
« on: July 26, 2017, 01:45:14 am »
This line of code isn't accepted by the compiler. (In the client code.)

sf::UdpSocket.send(packet, recipient, port);

So to simply put it, something is wrong with the code to send packets to the server.*

4
Network / Server and client UDP packet communication
« on: July 25, 2017, 11:43:04 pm »
Hello.

I got a little stuck when trying to setup a monitoring system sending all information to the server.

The idea is to use UDP and packets to simplify things, communication is only one-way.

This is what I've come up with so far, the idea is to be able to have a loop at the server side which spits out whatever comes in (cout), and if there is an error display that too.
#include <SFML/Network.hpp>
#include <iostream>

using namespace std;

int main() {

        sf::UdpSocket socket;

        // bind the socket to a port
        if (socket.bind(54000) != sf::Socket::Done) {
                cout << "There was an error binding to port 54000." << endl;
        }
        else {
                cout << "UDP socket is listening." << endl;
        }

        system("pause"); //Please ignore this, windows specific non-recommended stuff.
        return 0;
}

And on the client side I just want to send some information.
#include <SFML/Network.hpp>
#include <iostream>

using namespace std;

int main() {

        sf::IpAddress recipient = "127.0.0.1";
        unsigned short port = 54000;

        string message = "Hello";
        double speed = 10.3345;

        sf::Packet packet;

        packet << message << speed;
        sf::UdpSocket.send(packet, recipient, port); // This is the line VS 2015 don't like*

        system("pause"); //Please ignore this, windows specific non-recommended stuff.
        return 0;
}

My coding skills are rather basic, but I'm missing something here.

Thank you for anyone taking their time to help me out. :)

For the record, I used these pages when trying to set it up.
https://www.sfml-dev.org/tutorials/2.4/network-socket.php
https://www.sfml-dev.org/tutorials/2.4/network-packet.php

Pages: [1]
anything