Iam trying to send a message from my server app to the client app. The client app is connected to the server and the client and the server run on the same machine. What Iam doing is:
The above code doesnt work and WSAGetLastError () returns 0. Whats wrong with it? Cannt we bind a socket to a particular address and using that send a message?Code:SOCKET s; s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == INVALID_SOCKET) { return; } sockaddr_in sendto; sendto.sin_addr.s_addr = inet_addr ("127.0.0.1"); sendto.sin_family = AF_INET; sendto.sin_port = htons (nPort); //we only have the port address of the client if (bind (s, (sockaddr *)&sendto, sizeof (sendto)) == SOCKET_ERROR) { return; } char buffer [512]; sprintf (buffer, "Hi!"); if (send (s, buffer, strlen (buffer), 0) == SOCKET_ERROR) { int n = WSAGetLastError (); return; }




Reply With Quote