Connect two client sockets
- by Hernán Eche
Good morning, let's say Java has two kind of sockets...
server sockets "ServerSocket"
client sockets or just "Socket"
////so Simple !
Imagine the situation of two processes:
X Client <-- Y Server
The server process Y : has a "ServerSocket", that is listening to a TCP port
The client process X : send a connection request through a -client type- "Socket" X
////so Simple !
then the accept() method (in server Y) returns a new client type "Socket",
when it occurs, great the two Sockets get "interconected",
so
the -client socket- in client process, is connected with
the -client socket- in the server process
then (reading/writing in socket X is like reading/writing in socket Y, and viceversa. )
TWO CLIENT SOCKETS GET INTERCONECTED!!
////so Simple !
BUT... (there is always a But..)
What if I create the two CLIENT sockets in same process,
and I want to get them "interconected" ?
////mmm Complex =(... even posible?
Let's say how to have TWO CLIENT SOCKETS GET INTERCONECTED
WITHOUT using an intermediate ServerSocket ?
I 've solved it.. by creating two threads for continuously reading A and writing B,
and other for reading B and writng A...
but I think could be a better way..(or should!)
(Those world-energy-consuming threads are not necessary with the client-server aproach)
Any help or advice would be appreciated!! Thanks