Hello everyone,
I've been trying to setup a simple UDP server and client but I've got this one issue.
I would like to make it so that the server sends a message back to the client after the server has received a message from that client.
It would go like this.
- Client sends message to server.
- Server receives message. Sends another message back to client.
- Client receives message.
My idea is that the client will send a command to the server for example. Like a request.
The server would then send a packet back to the client containing the requested information.
For example position info.
I might be doing it all wrong and if so. Please feel free to take out the hammer and bash my brains in.
:)
Client (area that is most likely responsible for the issue)
//Listen for connection on port ...
ClientSocket.Bind(0);
char Buffer2[128];
size_t Received;
sf::IPAddress Sender;
unsigned short Port;
//Receive data from server
if(ClientSocket.Receive(Buffer2,sizeof(Buffer2),Received,Sender,Port) == sf::Socket::Done)
{
std::cout<<Buffer2<<std::endl;
}
Client console output
Failed to receive data ; the UDP socket first needs to be bound to a port
The 'Socket' sample code only does both sending and receiving for the TCP portion.
I'm using UDP.
Main problem with my code is that I don't know how to make get the client to receive the message from the server.
Which is most likely caused by the port I'm trying to bind it to.
I set it to port 0 because I don't know how to get the port the server will be sending the message to.
It seems that only the server knows which port the client used to communicate with it.
//Listen for connection on port ...
ClientSocket.Bind(0);
char Buffer2[128];
size_t Received;
sf::IPAddress Sender;
unsigned short Port;
//Receive data from server
if(ClientSocket.Receive(Buffer2,sizeof(Buffer2),Received,Sender,Port) == sf::Socket::Done)
{
std::cout<<Buffer2<<std::endl;
}