CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2004
    Posts
    4

    Multiple sockets

    Hi,
    I have developed an application using an overridden CAsyncSocket class to acquire data from a server. Now I need to get data from more than a single server. If I use multiple sockets for the client, I don't know how to distinguish which socket's OnConnect( ), OnSend( ) etc events are called. Is there some kind of way to identify the individual sockets? I tried adding an id datamember to the derived class and initialise it whenever I create and connect a new socket. But I still dont know how to retrieve its value in the OnConnect( ) etc as they seem to be event handlers and use if the "this" pointer doesn't work as they aren't member functions.

    Any insight ?

  2. #2
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Multiple sockets

    Quote Originally Posted by srikbond
    .... But I still dont know how to retrieve its value in the OnConnect( ) etc as they seem to be event handlers and use if the "this" pointer doesn't work as they aren't member functions....
    I'm not really certain that I understand your question. In fact, the OnXxxx functions like OnSend and OnConnect are indeed member functions for which the "this" pointer should serve to distinguish one object from another.

    Could you try explaining your question in a different way?

    Mike

  3. #3
    Join Date
    Nov 2004
    Posts
    4

    Re: Multiple sockets

    Hi Mike,
    Sorry my mistake. I meant to say that those On..() are called explicitly by the framework to notify the respective events.
    I use 2 sockets in my client application to connect to 2 servers. I am able to send data from them to the servers requesting for responses.
    At the servers, I am able to receive the requests and I reply with whatever data is requested.
    Now comes my problem. At the client side, OnReceive() , I either keep getting a failed assertion or nothing. I use my own class MySocket derived from CAsyncSocket and declare objects of MySocket in the doc file of the app. And which socket object to use for the Receive function inside OnReceive() ?

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Multiple sockets

    You should post code. Reading code and finding small mistakes is a lot easier than to "read" out the mistake by our explanations.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    Nov 2004
    Posts
    4

    Re: Multiple sockets

    Hi,
    I have attached a sample application which is a part of my actual application. In this app, OnReceive never seems to get called on the client side. I run a sample app on the server which sends back the system time at the server.
    This is similar to the scenario of my actual app.
    Attached Files Attached Files

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