Originate TCP messages from either end?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Originate TCP messages from either end?

  1. #1
    Join Date
    Jul 2012
    Posts
    3

    Originate TCP messages from either end?

    Hi

    I need a half-duplex TCP/IP channel, to carry info in either direction but only in one direction at a time. I can't predict which end will originate the message that starts a session, so whenever the channel's not in use each end must be listening continuously for the other.

    Using, say, .NET remoting I've done this with a listener - a server - that also exposes an event, so either end can originate a message to the other: the server by raising an "I have a message for the client" event, to which the client responds; or the client by calling an "I have a message for the server" method on the server.

    In this case I don't have the luxury of .NET remoting and must use TCP/IP sockets. Is there really no option but to put both a server and a client at each end, with each server listening on a different port? I can't see any other way to allow either end to originate a session.

    TIA.

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

    Re: Originate TCP messages from either end?

    Quote Originally Posted by lloydb View Post
    Hi

    I need a half-duplex TCP/IP channel, to carry info in either direction but only in one direction at a time. I can't predict which end will originate the message that starts a session, so whenever the channel's not in use each end must be listening continuously for the other.
    I don't fully follow your question. Regardless of which endpoint initiates a TCP connection, the conversation after connection is always two-directional. For example, even if endpoint 1 is the one that initiates the connection to endpoint 2 (i.e., endpoint 1 calls connect() and endpoint 2 calls listen() and accept()), both endpoints can always call both send() and recv().

    What are you trying to accomplish?

  3. #3
    Join Date
    Jul 2012
    Posts
    3

    Re: Originate TCP messages from either end?

    Quote Originally Posted by MikeAThon View Post
    I don't fully follow your question. Regardless of which endpoint initiates a TCP connection, the conversation after connection is always two-directional. For example, even if endpoint 1 is the one that initiates the connection to endpoint 2 (i.e., endpoint 1 calls connect() and endpoint 2 calls listen() and accept()), both endpoints can always call both send() and recv().

    What are you trying to accomplish?
    Hi Mike, thanks for replying. You're right of course: once a TCP connection's established, messages can originate from either end. But that's different from being able to originate the connection itself from either end. Because only the listener listens, only the client can kick off the establishment of a connection (by calling connect()). That means if the listener has a message for the client, either:

    - the connection must be long-lived and already established, so the listener can call send(); or
    - the client must also be listening, so the listener can call connect() and establish a connection; or
    - the client must periodically connect to and poll the listener in case the listener has any messages waiting for the client.

  4. #4
    Join Date
    Feb 2012
    Location
    Fremont,CA
    Posts
    36

    Re: Originate TCP messages from either end?

    The TCP three-way handshake in Transmission Control Protocol (also called the TCP-handshake; three message handshake and/or SYN-SYN-ACK) is the method used by TCP set up a TCP/IP connection over an Internet Protocol based network.
    Make sure you check out my >>Facebook Development Blog and Website<<

  5. #5
    Join Date
    Mar 2001
    Posts
    2,374

    Re: Originate TCP messages from either end?

    Lloyd, here is a link to the source code that you require:
    http://cs.ecs.baylor.edu/~donahoo/pr.../textcode.html
    Also it is the link to the author guide to TCP/IP Sockets in C, which is a very good book on the subject.
    The source will also run on the Windows platform.

    Shoot! Another old post. Is this list dying?
    Last edited by ahoodin; October 16th, 2012 at 08:36 AM.
    ahoodin
    To keep the plot moving, that's why.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center