CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Fd_oob?

  1. #1
    Join Date
    Nov 2001
    Location
    Beijing, China
    Posts
    69

    Fd_oob?

    Hello,

    Could anyone tell me what does FD_OOB mean? When TCP client application quit, my TCP server application in VC++ receives this event.


    Thanks and best regards,
    connie

  2. #2
    Join Date
    Nov 2001
    Location
    Beijing, China
    Posts
    69

    Re: Fd_oob?

    Forgot to say NetworkEvents.lNetworkEvents=2. Is it FD_OOB?


    connie

  3. #3
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: Fd_oob?

    No. FD_OOB is 4, and it means Out Of Band Data. Generaly, you shouldn't be worring about OOB. You get it only if you have marked it as one(to say the least).
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  4. #4
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: Fd_oob?

    Forgot to mention. 2 is FD_WRITE.
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  5. #5
    Join Date
    Nov 2001
    Location
    Beijing, China
    Posts
    69

    Re: Fd_oob?

    Thank you very much, Mathew Joy.

    My TCP server application continously receives FD_CONNECT, as I described in another thread (WSAEnumNetworkEvents) , how is that? Do you have any idea? Could you please give me a piece of advice?


    connie

  6. #6
    Join Date
    Feb 2003
    Location
    Bangalore, India
    Posts
    1,354

    Re: Fd_oob?

    Are you trying for a connect? Are you sure you are talking about FD_CONNECT and not FD_WRITE? Because above you say you are getting NetworkEvents.lNetworkEvents=2. And did you check the return value of the WSAEnumNetworkEvent()? If it is non-zero value you have to get the error number thru a call to WSAGetLastError().
    Even if our suggestions didn't help, please post the answer once you find it. We took the effort to help you, please return it to others.

    * While posting code sections please use CODE tags
    * Please check the codeguru FAQ and do a little search to see if your question have been answered before.
    * Like a post, Rate The Post
    * I blog: Network programming, Bible

    I do all things thru CHRIST who strengthens me

  7. #7
    Join Date
    Nov 2001
    Location
    Beijing, China
    Posts
    69

    Re: Fd_oob?

    Hello,

    Let me make it clear.

    My application is a TCP server. I want to be notified when TCP client connects, sends or disconnects. I used WSAWaitForMultipleEvents() in my application.

    I tested again and again and found that while(b_ServerStop!=true)
    {
    ......
    }

    in my TCP server application sometimes goes into infinite loop. Please find it at the end of my message.

    I tested with my code and a sample VC++ TCP client application. I kept my TCP server application running. The client would do connect(), send(), shutdown(), step by step, then I closes this client application. Then I restarted the client.

    I found that my application worked well for the first time the client connected,but when I restarted the client and the client connect(), my application continuously receive network event after client connect(),NetworkEvents.lNetworkEvents=8, then goes into infinite loop. I checked the return value of WSAEnumNetworkEvents(), when I found it goes to -1, I used WSAGetLastError(), and the return value is 10038, WSAENOTSOCK.

    How is that? Why does the same TCP server code and the client code work well for the first time and not the second time?

    while(b_ServerStop!=true)
    {
    ret=WSAWaitForMultipleEvents(EventTotal,EventArray,FALSE,WSA_INFINITE,FALSE);

    if ((ret!=WSA_WAIT_FAILED) && (ret!=WSA_WAIT_TIMEOUT))
    {
    Index=ret-WSA_WAIT_EVENT_0;
    for (int i=Index;i<EventTotal;i++)
    {
    Index=WSAWaitForMultipleEvents(1,&EventArray[i],TRUE,1000,FALSE);
    int b=WSAGetLastError();

    if ((Index!=WSA_WAIT_FAILED) && (Index!=WSA_WAIT_TIMEOUT))
    {
    Index=i;
    b=WSAEnumNetworkEvents(SockArray[Index],EventArray[Index],&NetworkEvents);
    b=WSAGetLastError();

    if(NetworkEvents.lNetworkEvents==FD_ACCEPT && b==0)
    {

    if (pdlg_sevr->SocketCheck(server,SC_READ))
    {
    WSAEVENT newclientevent;
    newclientevent=WSACreateEvent();

    client=accept(server,
    (struct sockaddr*)&from,&fromlen);

    WSAEventSelect(client,newclientevent,FD_READ|FD_WRITE|FD_CLOSE);

    SockArray[EventTotal]=client;
    EventArray[EventTotal]=newclientevent;
    EventTotal++;

    tempIPaddr=inet_ntoa(from.sin_addr) ;
    client_port=from.sin_port ;

    if (tempIPaddr==cs_valid_clientip1 || tempIPaddr==cs_valid_clientip2)
    {
    // EnterCriticalSection(&CThpDlg::m_Lock_cnt);
    connect_count++;
    // LeaveCriticalSection(&CThpDlg::m_Lock_cnt);

    if (connect_count<4)
    {
    idService_recv=AfxBeginThread(RecvThread,(LPVOID)client);
    idService_send=AfxBeginThread(SendThread,(LPVOID)client);

    if (idService_recv==NULL || idService_send==NULL)
    closesocket(client);
    }

    }
    else //if IP addr incorrect, close invalid connection //LY 2004.3.2
    {
    closesocket(client);
    connect_count=0;
    b_close=1;
    NS=0;
    NR=0;
    b_open_real=0;
    b_open_soe=0;

    }
    }
    }
    else if(NetworkEvents.lNetworkEvents==FD_CLOSE)
    {
    closesocket(client);
    connect_count=0;
    b_close=1;
    NS=0;
    NR=0;
    b_open_real=0;
    b_open_soe=0;
    //EventTotal--;
    }
    }
    }
    }
    Sleep(1000);

    }//end of while loop


    Thanks and best regards,
    connie

  8. #8
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664

    Re: Fd_oob?

    Please use the CODE tags...

    Had a quick look at your code and is wondering why you call WSAWaitForMultipleEvents twice?

    The second call makes the lookup in SockArray to always hit index = 0... A bug... Haven't looked further down in the code.

  9. #9
    Join Date
    Nov 2001
    Location
    Beijing, China
    Posts
    69

    Re: Fd_oob?

    Hello,

    Thanks for your reply.

    I commented out the second WSAWaitForMultipleEvents(), but it still did not work. It was the same.

    The problem is when the TCP client sent out the connect() for the second time, my TCP server continously receive network event, that is the first WSAWaitForMultipleEvents() always receives event.

    By the way, what is CODE tag?


    Thanks again.


    connie

  10. #10
    Join Date
    Aug 2001
    Location
    Stockholm, Sweden
    Posts
    1,664

    Re: Fd_oob?

    The codes tags makes source lists to be displayed nicely formatted in the posts. Ex:
    Code:
    int main()
    {
        puts("Nicely formatted piece of code...");
        return 0;
    }
    Put CODE within [ ] to begin the code section.
    Put /CODE within [ ] to end the code section.

    Back to your problem:

    Try add some debug tracing etc... And post a new version of your code (within CODE tags), and I'll promise you to have a second look at it.

  11. #11
    Join Date
    Nov 2001
    Location
    Beijing, China
    Posts
    69

    Re: Fd_oob?

    Hi,

    Sorry, I did not quite catch up with you on how to make code tags.

    Hope the following looks better.

    while(b_ServerStop!=true)
    {
    ret=WSAWaitForMultipleEvents (EventTotal,EventArray,FALSE,WSA_INFINITE,FALSE);

    if ((ret!=WSA_WAIT_FAILED) && (ret!=WSA_WAIT_TIMEOUT))
    {
    Index=ret-WSA_WAIT_EVENT_0;
    for (int i=Index;i<EventTotal;i++)
    {
    Index=WSAWaitForMultipleEvents(1,&EventArray[i],TRUE,1000,FALSE);
    int b=WSAGetLastError();

    if ((Index!=WSA_WAIT_FAILED) && (Index!=WSA_WAIT_TIMEOUT))
    {
    Index=i;
    b=WSAEnumNetworkEvents(SockArray[Index],EventArray [Index],&NetworkEvents);
    b=WSAGetLastError();

    if(NetworkEvents.lNetworkEvents==FD_ACCEPT )
    {

    if (pdlg_sevr->SocketCheck(server,SC_READ))
    {
    WSAEVENT newclientevent;
    newclientevent=WSACreateEvent();

    client=accept(server,
    (struct sockaddr*)&from,&fromlen);

    WSAEventSelect(client,newclientevent,FD_READ|FD_WRITE|FD_CLOSE);

    SockArray[EventTotal]=client;
    EventArray[EventTotal]=newclientevent;
    EventTotal++;

    tempIPaddr=inet_ntoa(from.sin_addr) ;
    client_port=from.sin_port ;

    if (tempIPaddr==cs_valid_clientip1 || tempIPaddr==cs_valid_clientip2)
    {
    connect_count++;

    if (connect_count<4)
    {
    idService_recv=AfxBeginThread(RecvThread,(LPVOID)client);
    idService_send=AfxBeginThread(SendThread,(LPVOID)client);

    if (idService_recv==NULL || idService_send==NULL)
    closesocket(client);
    }
    }

    else //if IP addr incorrect, close invalid connection
    closesocket(client);

    }
    }
    else if(NetworkEvents.lNetworkEvents==FD_CLOSE)
    closesocket(client);

    }
    }
    }
    Sleep(1000);

    }//end of while loop



    Thanks.
    connie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured