Results 1 to 4 of 4

Thread: Some network confusion

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    3

    Some network confusion

    I'm trying to build a simple network program to send data back and forth. I'm using this example here:

    http://vb.net-informations.com/commu...ent_Socket.htm

    Now, I have the server in another project set up and working. I have this program working as well. But my concern is this: if I'm reading the code right, the client program (above) only reacts to data coming in right after sending some data (as part of the button click event). It would not react to any new data coming in unsolicited. For my application, it will need to be able to send data at any time, as well as react to data coming in that is not necessarily preceded by sending data. How would I accomplish this? Go easy on me, I just started fooling around in VB a few days ago!

    Thanks!

    Dan

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Some network confusion

    You need to create a TCP Listener object. If you search the forum you'll find plenty of examples (there's usually roughly one post a day on the subject!)

    Also when you look at the code you have already, you'll see that your server is using a TCP Listener (hence its own ability to receive unsolicited messages). It is exactly the same principle for the client.
    Last edited by keystone_paul; Apr 19th, 2009 at 02:02 PM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    3

    Re: Some network confusion

    Thanks Paul. I've been reading a lot and messing around but I still haven't figured out what to do.

    I think what I need to do is create a network stream, then have a listener function running in its own thread, and also have separate functions to send? Then have the listener loop until there is some data and do something with it? I'm just very confused as to how to go about it. Can I send while it's listening?

    Any pointers would be much appreciated. I know this has probably been discussed before but in the searches I've done I haven't really found a way to apply this to make a solution.

    Basically, I am just looking to find how to make a client that will:

    1. Connect to a server
    2. Be able to send commands.
    3. Listen for incoming data, and if it gets it, do something with it. This data may be unsolicited.

    Like I said, any help much appreciated. I'm still learning!

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    3

    Re: Some network confusion

    Nevermind, I found some references to BeginRead and followed up on that. Have it working now!

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