Unicode vurses Non Unicode client server application with winsock2 query?

This is a discussion on Unicode vurses Non Unicode client server application with winsock2 query? within the Networking/Device Communication forums, part of the General Programming Boards category; Hi I have a client server application(UNICODE). Server being dialog based mfc app. Client being sdi mfc app. both r ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    17

    Client Server Application (UNICODE) -- client not receiving FD_CLOSE notification?

    Hi

    I have a client server application(UNICODE).
    Server being dialog based mfc app.
    Client being sdi mfc app.

    both r asynchronous in nature due to use of WSAAsyncSelect().

    My problem is that the client donot receives the FD_CLOSE notification when the server closes its socket.

    The server donot faces such a problem. It is notified when the client closes its socket.

    I m pasting the code on the client side:

    Client pressing the File->Connect sub menu item:

    Code:
    void CMainFrame::OnConnect() 
    {
    WSADATA wsaData;
    sockaddr_in local;
    
    unsigned int addr;
    struct hostent *hp;
    
    const char* sname = "172.16.110.13";
    
    WORD wVersionRequested = MAKEWORD(2,2);
    
    int wsaret = WSAStartup(wVersionRequested, &wsaData); 
    
    if(wsaret != 0) 
    AfxMessageBox(_T("WSAStartup() failed!"));
    else
    {
    AfxMessageBox(_T("Winsock version 2.2 dll loaded. "));
    
    
    if(inet_addr(sname)==INADDR_NONE)
    {
    hp=gethostbyname(sname);
    }
    else
    {
    addr=inet_addr(sname);
    hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);
    }
    
    local.sin_family = AF_INET;
    local.sin_addr.s_addr = *((unsigned long*)hp->h_addr);
    local.sin_port = htons((u_short)40000);
    
    client = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    
    if(client != INVALID_SOCKET)
    {
    AfxMessageBox(_T("Client socket created successfully!"));
    
    
    if(WSAAsyncSelect(client, m_hWnd, WM_WINSOCK_NOTIFY, FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE) == SOCKET_ERROR) 
    AfxMessageBox(_T("WSAAsyncselect() failed to xecute!")); 
    else
    AfxMessageBox(_T("WSAAsyncselect() xecuted successfully!")); 
    
    
    int ret = connect(client, (sockaddr*)&local, sizeof(local));
    
    if(ret == SOCKET_ERROR)
    {
    ret=0;
    ret = WSAGetLastError();
    
    if(ret == WSAEWOULDBLOCK)
    {
    AfxMessageBox(_T("This kind of error is normal with Asynchronous sockets. It is a non fatal error."));
    }
    else
    {
    //some major error.
    AfxMessageBox(_T("Unable to connect with the server!"));
    closesocket(client);
    WSACleanup();
    return; 
    }
    }
    
    else
    {
    AfxMessageBox(_T("Successful connection with server is established!"));
    
    }
    }
    }
    }
    
    
    My message handler:
    LRESULT CMainFrame::OnWinsockNotify(WPARAM wParam, LPARAM lParam)
    {
    int nError = WSAGETASYNCERROR(lParam);
    
    if (nError != 0)
    {
    switch (nError)
    {
    case WSAECONNRESET:
    AfxMessageBox(_T("Connection was aborted."));
    //CloseSocket();
    break;
    
    case WSAECONNREFUSED:
    AfxMessageBox(_T("Connection was refused."));
    //CloseSocket();
    break;
    }
    return 0;
    }
    
    nError = 0;
    nError = (int)WSAGETSELECTEVENT(lParam);
    
    switch (nError)
    {
    case FD_READ:
    {
    AfxMessageBox(_T(Data is ready tobe read!)); 
    break;
    }
    
    case FD_WRITE:
    AfxMessageBox(_T("Send some data to the server!"));
    break;
    
    case FD_CONNECT:
    {
    AfxMessageBox(_T("The server accepts the connection!"));
    break;
    }
    
    case FD_CLOSE:
    AfxMessageBox(_T("The server has closed his socket!"));
    break; 
    }
    return 0;
    }
    waiting for suggestions

    Regards
    Last edited by dp_76; 05-17-2005 at 01:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiple forks in one client connection (ftpclient)
    By Dynamo in forum Networking/Device Communication
    Replies: 5
    Last Post: 01-16-2011, 11:41 AM
  2. Chat Program Help?
    By Paul22000 in forum Networking/Device Communication
    Replies: 9
    Last Post: 02-09-2009, 11:35 PM
  3. socket newbie, losing a few chars from server to client
    By registering in forum Linux Programming
    Replies: 2
    Last Post: 06-07-2003, 11:48 AM
  4. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM
  5. [SOCKETS] Solaris server in C, NT client in VB
    By Daveg27 in forum C Programming
    Replies: 3
    Last Post: 05-23-2002, 10:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21