server/ client server connection

Posted by user312054 on Stack Overflow See other posts from Stack Overflow or by user312054
Published on 2010-04-30T19:34:56Z Indexed on 2010/04/30 19:37 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

I have a server side program that creates a listening server side socket. The problem occurring is that it seems as if the client side sends a connect request it gets rejected if the server side socket is listening but connects if the server side program is not running. I can see the server side program getting the client request when debugging. It seems as if the client cannot connect to a listening socket. Any suggestions on a resolution?

The server side accept code snippet is this.

    void CSocketListen::OnAccept(int nErrorCode)
    {
    CSocket::OnAccept(nErrorCode);

   CSocketServer* SocketPtr = new CSocketServer();
    if (Accept(*SocketPtr))
    {
         // add to  list of client sockets connected
    }
    else
   {
        delete SocketPtr;
   }

The client side code connect is like this.

    SOCKET cellModem;  
    sockaddr_in handHeld;
    handHeld.sin_family = AF_INET; //Address family    
    handHeld.sin_addr.s_addr = inet_addr("127.0.0.1");    
    handHeld.sin_port = htons((u_short)1113); //port to use

    cellModem=socket(AF_INET,SOCK_STREAM,0);    

    if(cellModem == INVALID_SOCKET)
    {
      // log socket failure
      return false;
    }
    else
    {
     // log socket success
    }


   if (connect(cellModem,(const struct sockaddr*)&handHeld, sizeof(handHeld)) != 0 )
   {
     // log socket connection success   
   }
   else
   {
     // log socket connection failure
     closesocket(cellModem);
   }

© Stack Overflow or respective owner

Related posts about client

Related posts about server