Hi.
I try to make client and server on UDP.
Client:
int ServPort = 1337; //Port Servera
IPAddress ServIP("127.0.0.1"); //IP Servera, moze byc HOST
if (!ServIP.IsValid()){
cout << "Niepoprawny adres serwera" << endl;
}
SocketUDP Client;
char Message[] = "Hi, I'm a client !";
if (Client.Send(Message, sizeof(Message), ServIP, ServPort) != Socket::Done)
cout << "Pierdolony error!" << endl;
else
cout << "Message sent to server : \"" << Message << "\"" << endl;
Client.Close();
and Server:
IPAddress SenderIP;
unsigned short SenderPort;
while (true)
{
unsigned int NbSockets = Selector.Wait();
for (unsigned int i = 0; i < NbSockets; ++i)
{
SocketUDP Socket = Selector.GetSocketReady(i);
sf::Packet Packet;
if (Socket.Receive(Packet, SenderIP, SenderPort) == sf::Socket::Done)
{
// Extract the message and display it
float x;
float y;
Packet >> x >> y;
std::cout << SenderIP << ":"<< SenderPort << " " << x << " " << y << std::endl;
}
else
{
// Error : we'd better remove the socket from the selector
Selector.Remove(Socket);
}
}
}
And server dont gets a message from client. Whats wrong?