Note that there are some explanatory texts on larger screens.

plurals
  1. POCommunication betwen Client and Servver running on two different machines using UDP Sockets in C using Visual studio 2008
    primarykey
    data
    text
    <p>I have developed an application in which a client and server can communicate with eachother using UDP Sockets. I have used loop Back address on Client side and INADDR_ANY for the Server Side. The program works fine on the same machine. But when I tried to run the Client from a different machine, the communication failed. here is the code snippet: <strong>SERVER:</strong></p> <pre><code> #define PORT 8888 //The port on which to listen for incoming data if (WSAStartup(MAKEWORD(2,2),&amp;wsa) != 0) { exit(EXIT_FAILURE); } ///Create a socket/// if((socketIdentifier = socket(AF_INET , SOCK_DGRAM , 0 )) == INVALID_SOCKET) { //"Socket not created" } ///Socket Created/// ///Prepare the sockaddr_in structure/// serverSocket.sin_family = AF_INET; serverSocket.sin_addr.s_addr = INADDR_ANY; serverSocket.sin_port = htons( PORT ); ///Bind/// if( bind(socketIdentifier ,(struct sockaddr *)&amp;serverSocket , sizeof(serverSocket)) == SOCKET_ERROR) { //"Bind Failed" } ///Bind Done/// if((recv_len = recvfrom(socketIdentifier, receiveBuffer, sizeof(receiveBuffer), 0, (struct sockaddr *) &amp;clientSocket, &amp;clientSocketLength)) == SOCKET_ERROR) { "Could not Receive Data" } hDeviceContext = BeginPaint(AH_Glb_windowHandle, &amp;ps ); TextOut(GetDC(AH_Glb_windowHandle),10,10+i,receiveBuffer,recv_len); EndPaint( AH_Glb_windowHandle, &amp;ps ); </code></pre> <p><strong>CLIENT:</strong></p> <pre><code> #define PORT 8888 //The port on which to listen for incoming data #define SERVER "58.65.172.11" //ip address of udp server ///Initialise winsock/// if (WSAStartup(MAKEWORD(2,2),&amp;wsa) != 0) { //Socket Initialization Failed/// exit(EXIT_FAILURE); } ///create socket/// if ((socketIdentifier=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == SOCKET_ERROR) { ///Socket Creation Failed/// exit(EXIT_FAILURE); } ///setup address structure/// memset((char *) &amp;connectedSocket, 0, sizeof(connectedSocket)); connectedSocket.sin_family = AF_INET; connectedSocket.sin_port = htons(PORT); connectedSocket.sin_addr.S_un.S_addr = inet_addr(SERVER); if (sendto(socketIdentifier,sendBuffer,strlen(sendBuffer) , 0 , (struct sockaddr *) &amp;connectedSocket, sizeof(connectedSocket)) == SOCKET_ERROR) { MessageBox(NULL, "Sending Failed", "Failure", MB_ICONINFORMATION); exit(EXIT_FAILURE); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload