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

Author Topic: UDP packet not received by server  (Read 1768 times)

0 Members and 1 Guest are viewing this topic.

user

  • Newbie
  • *
  • Posts: 6
    • View Profile
UDP packet not received by server
« 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!!!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
UDP packet not received by server
« Reply #1 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.
Laurent Gomila - SFML developer

user

  • Newbie
  • *
  • Posts: 6
    • View Profile
how to do that?
« Reply #2 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
UDP packet not received by server
« Reply #3 on: February 21, 2011, 01:27:44 pm »
Quote
u mean i cant run both on the same machine?

Of course you can ;)
Laurent Gomila - SFML developer

user

  • Newbie
  • *
  • Posts: 6
    • View Profile
UDP packet not received by server
« Reply #4 on: February 22, 2011, 09:33:16 am »
Thanku Thanku Thanks a lot!!!!!!!  :)

 

anything