SFML community forums
Help => Network => Topic started by: user on February 20, 2011, 06:36:43 am
-
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!!!
-
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.
-
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?
-
u mean i cant run both on the same machine?
Of course you can ;)
-
Thanku Thanku Thanks a lot!!!!!!! :)