I'm writing an application that has to make a connection on a socket to a set IP and port. During the lifetime of this socket connection, I'm required to listen on a specific port and respond when a message is received on the same port.
The application is part of a complex multi threaded environment, and other threads are running during this process to enable user input.
My Application makes the initial connection on port X, and sends a message.
Starts the 'listener' thread on port Y.
Main execution thread carries on happily.
Once the Application receives a response on port X, the process is over.
Port Y needs to stay open and receive messages and send responses during the life time of port X, however I try and thread the client on port Y it closes itself once a message has been sent.
I've been looking at this for a couple of days, and I can't see a solution!
The listener is started on a seperate thread. Once a connection is made on Port Y, I create a TCPClient to handle the asynchronous call, then in the async method I do my work on a net stream (read and write back). At this point I think I need the netstream to stay open, but the calling thread opens a new stream and closes the existing one! The third party providers have told me the port is being closed by my application, and I can't see how to keep the listener thread netstream open!
Any logical help appreciated, or I'm going to be working over Christmas!!
regards
Matt