Working With Sockets
I have been tasked with creating an interface to a PBX. The PBX (client) will connect to my application (Server). I have created a listener class that waits for
messages from the client.
this.serverSocket = new ServerSocket(this.serverPort);
clientSocket = this.serverSocket.accept();
Upon receipt of the message I spawn a thread that will handle that message.
clientSocket, "MS: "+i)
From time to time I need to send messages to the client. What would be the best way to do this?
The client needs to ACK each message I send it.
I was thinking of creating a separate thread sendMsg(clientSocket) to handle this. So after I send my first message it (PBX) will ACK. Does this ACK stay in this thread or does it go to my listener class? If it goes to my listener class how do I know that the message I sent was ACKEed or some other message?
Re: Working With Sockets
Threads are one thing, socket connections are another.
I think You can read and write through a socket from different threads.
If you send a message through a socket and the program sends a response through the same socket, I don't think which thread did it will matter.
I don't know what happens if more than one thread tries to read from a socket at the same time.
Write a small test program and see what happens.