-
July 10th, 2012, 11:13 PM
#1
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.
-
July 16th, 2012, 08:29 PM
#2
Re: Originate TCP messages from either end?
Originally Posted by lloydb
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?
-
July 16th, 2012, 11:35 PM
#3
Re: Originate TCP messages from either end?
Originally Posted by MikeAThon
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.
-
October 15th, 2012, 12:07 AM
#4
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.
-
October 16th, 2012, 07:27 AM
#5
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 07: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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|