Professional Documents
Culture Documents
Discussion Forum Unit 6 Cs 2203
Discussion Forum Unit 6 Cs 2203
A
Socket can be a client socket that sends a connection request to a server. created by a server
to handle a connection request from a client. So a Socket can be used for a client and a server.
Eck, D. J. (2019) says, a ServerSocket listens for connection requests creates Sockets to handle
the actual connections. So a ServerSocket itself does not connect with a client.
When you construct a ServerSocket, listen for a connection request, and establish a
connection with a client, you can write as follows:
// continue listening
while (true){
someProcess(connection);
You should wrap the above code with try ... catch.
in = connection.getInputStream();
out = connection.getOutputStream();
You should also wrap the above code with try ... catch
When you construct a ServerSocket, you should specify the Port. When you specify a Socket,
you should specify the IP number or a domain name of the server and the port number of it.
Sockets have getInputStream method and getOutputStream method. You can communicate
with the server by these methods.
Reference:
Eck, D. J. (2019). Introduction to programming using Java, version 8.1. Hobart and William
Smith Colleges