Jump to content
  • Advertisement
Sign in to follow this  
Gnuttis

FD_CONNECT is not received in the client ?

This topic is 4850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to build an application. When it is started it should be possible to start it as a server or a client. It works in tfollowing way(first a server is started and then a client tries to connect) 1) SetupServer is called. Set every thing up for the server. Start listen. 2) When the client tries to connect. FD_ACCEPT event is received in the server. The server calls the AcceptClient(). No error is reported. As I understand, the client should receive the FD_CONNECT event now,but it doesn't. Could someone help me? Please...... (The socket was made non-blocking before connect() was called) ////////////////////////////////////////////////////// // SetupServer() ////////////////////////////////////////////////////// CClientServer::SetupServer(HWND m_hWnd) { ssockVersion = MAKEWORD(1, 1); int error = WSAStartup(ssockVersion, &swsaData); // Next, create the listening socket> listeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (listeningSocket == INVALID_SOCKET) { snret = WSAGetLastError(); WSACleanup(); } // Make the port non-blocking WSAAsyncSelect(listeningSocket,m_hWnd,WM_USER+5,FD _OOB|FD_CLOSE|FD_ACCEPT|FD_READ|FD_WRITE|FD_CONNEC T); // Use a SOCKADDR_IN struct to fill in address information sserverInfo.sin_family = AF_INET; // Since this socket is listening for connections, // any local address will do sserverInfo.sin_addr.s_addr = INADDR_ANY; // Convert integer 5555 to network-byte order // and insert into the port field sserverInfo.sin_port = htons(5555); // Bind the socket to our local server address snret = bind(listeningSocket, (LPSOCKADDR)&sserverInfo, sizeof(struct sockaddr)); if (snret == SOCKET_ERROR) { snret = WSAGetLastError(); WSACleanup(); } snret = listen(listeningSocket, 5); if (snret == SOCKET_ERROR) { snret = WSAGetLastError(); WSACleanup(); } } ////////////////////////////////////////////////////// // AcceptClient() ////////////////////////////////////////////////////// CClientServer::AcceptClient(void) { // A client has connected. int sin_size; sin_size = sizeof(sockaddr_in); int addr_size = sizeof (sockaddr); theClient = accept(listeningSocket, (struct sockaddr *)&their_addr, &sin_size); if (theClient== INVALID_SOCKET) { snret = WSAGetLastError(); WSACleanup(); } } ////////////////////////////////////////////////////// // Method: ConnectToServer() // // Description: ////////////////////////////////////////////////////// CClientServer::ConnectToServer(void) { // Try to connect to server csockVersion = MAKEWORD(1, 1); // Initialize Winsock as before WSAStartup(csockVersion, &cwsaData); // Store information about the server iaHost.s_addr = inet_addr("162.138.0.49"); chostEntry = gethostbyaddr((const char *)&iaHost, sizeof(struct in_addr), AF_INET); if (!chostEntry) { cnret = WSAGetLastError(); WSACleanup(); } // Create the socket ctheSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ctheSocket == INVALID_SOCKET) { cnret = WSAGetLastError(); WSACleanup(); } // Make the port non-blocking WSAAsyncSelect(ctheSocket,m_hWnd,WM_USER+5,FD_CLOS E|FD_READ|FD_WRITE|FD_CONNECT); // Fill a SOCKADDR_IN struct with address information cserverInfo.sin_family = AF_INET; cserverInfo.sin_addr = *((LPIN_ADDR)*chostEntry->h_addr_list); // Change to network-byte order and // insert into port field cserverInfo.sin_port = htons(5555); // Connect to the server cnret = connect(ctheSocket, (LPSOCKADDR)&cserverInfo, sizeof(struct sockaddr)); if (cnret == SOCKET_ERROR) { cnret = WSAGetLastError(); WSACleanup(); } }

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!