|
Java™ by example!
|
|
|
How do I implement an echo Server in Java?
You can either use a TCP or UDP version. With UDP, you will have to use a DatagramSocket to create and listen to a port. With TCP (see example), you need to instantiate a ServerSocket. The echo port is 7. The server just creates a thread that loops indefinitely waiting for requests from clients and returns the exact same string the client contacted it with. To test out following server, compile the source of EchoClient (see EchoClient) and run it using
EchoServer.java:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|