June 2017
Intermediate to advanced
304 pages
7h 12m
English
Now, let's check out an example where we will establish a connection to the server with the help of a socket. This will demonstrate how data can be sent and received between the client and the server. The following example is a server application making use of the Socket class to listen to clients on a port number specified by a command-line argument:
//Socket Serverimport java.io.DataOutputStream;import java.io.IOException;import java.io.OutputStream;import java.net.ServerSocket;import java.net.Socket;public class SimpleSocketServer { public static void main(String args[]) throws IOException { // A new service registered with the 1286 port ServerSocket ss = new ServerSocket(1286); //Accept the connection request ...Read now
Unlock full access