thread communicationgreenspun.com : LUSENET : Java Programming : One Thread
I working with threads and java tcpsockets. the program is simple. once the connection is established between the two communicating servers. the reciving server forks a thread. but how do i distinguish between packets and how do i redirect them to the right thread that was created. (the ip address will not help because one server could send many diffrent packets)...
((Note : it is not forking a thread for every packet. but it forks a thread only for a particular packet and then the packets following that packet need to be directed to that specific thread)
-- mustafa santrampurwala (firstname.lastname@example.org), September 10, 2002
You should check out the ServerSocket and Socket classes. Your "parent" Thread (from which you create the new thread) should call the accept() method of a ServerSocket. This will return a Socket object that can be used by the new thread to communicate with the Socket that tried to connect to the "parent" Thread.
-- Andrei (email@example.com), January 07, 2003.