SFML community forums

Help => Network => Topic started by: user on February 20, 2011, 06:36:43 am

Title: UDP packet not received by server
Post by: user on February 20, 2011, 06:36:43 am
Code: [Select]
unsigned short Port=4567;
DoClientUDP(hWnd,Port);

void DoClientUDP(HWND hwnd,unsigned short Port)
{
  sf::IPAddress ServerAddress;
  ServerAddress=sf::IPAddress::LocalHost;

  while (!ServerAddress.IsValid());
 
  sf::SocketUDP Client;
  unsigned short CPort=4323;

  Client.Bind(CPort);

   char Message[3] = "Hi";

    if (Client.Send(Message, sizeof(Message),ServerAddress, Port) != sf::Socket::Done)
          return;
   else
   {
     DoServerUDP(hwnd);
     Client.Close();
   }
}

void DoServerUDP(HWND hwnd)
{
  unsigned short Port=4567;
  sf::SocketUDP Server;

 char Buffer[200]="";
 std::size_t Received;

 sf::IPAddress ClientAddress=sf::IPAddress::LocalHost;
 
 unsigned short ClientPort;
 char Message[3]="";

 if (!Server.Bind(Port))
        return;
 Server.SetBlocking(false);

 sf::Socket::Status SocketStatus=sf::Socket::Done;
 SocketStatus=(Server.Receive(Message, sizeof(Message), Received, ClientAddress, ClientPort));

Server.Close();

}



This is my code. Now when i execute the statement(Server.Receive), the SocketStatus becomes NotReady.The client sends the message but the server does not receive it.What should be done???Please HELP!!!
Title: UDP packet not received by server
Post by: Laurent on February 20, 2011, 10:26:21 am
You execute the client *then* the server, they can't communicate.
The server must be running when the client sends the message, in other words you must execute both at the same time.
Title: how to do that?
Post by: user on February 21, 2011, 12:21:05 pm
u mean i cant run both on the same machine?if not, then can u please tell me how to connect two machines and make the code run?
Title: UDP packet not received by server
Post by: Laurent on February 21, 2011, 01:27:44 pm
Quote
u mean i cant run both on the same machine?

Of course you can ;)
Title: UDP packet not received by server
Post by: user on February 22, 2011, 09:33:16 am
Thanku Thanku Thanks a lot!!!!!!!  :)