Package var.sockets.tcp.echo
Class EchoServerIterativ
- java.lang.Object
-
- var.sockets.tcp.echo.EchoServerIterativ
-
public class EchoServerIterativ extends java.lang.Object
iterative server for var.sockets.tcp.echo Echo service. waits for the next client to connect, sends greeting message to client, reads line by line from client and sends it back adding "echo: " in front of each line until connection is closed by client.- Author:
- Sandro Leuchter
-
-
Constructor Summary
Constructors Constructor Description EchoServerIterativ(int port, int backlog)
the only constructor for this class
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
handleClient(java.net.ServerSocket server)
waits for the next client to connect to server, sends greeting message to client, reads line by line from client and sends it back adding "echo: " in front of each line until connection is closed by client.static void
main(java.lang.String[] args)
main method: entrypoint to run servicevoid
start()
creates server socket on localhost:port, infinitely handles connections to clients one after another
-
-
-
Constructor Detail
-
EchoServerIterativ
public EchoServerIterativ(int port, int backlog)
the only constructor for this class- Parameters:
port
- port on which this service will be listening on localhostbacklog
- requested maximum length of the queue of incoming connections.
-
-
Method Detail
-
start
public void start()
creates server socket on localhost:port, infinitely handles connections to clients one after another
-
handleClient
private void handleClient(java.net.ServerSocket server)
waits for the next client to connect to server, sends greeting message to client, reads line by line from client and sends it back adding "echo: " in front of each line until connection is closed by client.- Parameters:
server
- "welcome socket" on which server is listening for clients
-
main
public static void main(java.lang.String[] args)
main method: entrypoint to run service- Parameters:
args
- args[0] must be the port number of the server (int); rest of args is ignored
-
-