Posts

Socket Programming

 A sample program to create a server which returns the date time . A socket is created which listens port 13. A connection is established when it accepts a client.  Server writes to the connection using output stream to communicate with the client. Once its time to close the connection, both server and client closes the connection and server waits for next connection.     DatetimeServer.java import java.net.* ; import java.io.* ; import java.util.Date ; public class DatetimeServer {    public final static int port = 13 ;   public static void main(String args[]) {       try (ServerSocket server = new ServerSocket(port)) {          while ( true ) {             try (Socket connection = server.accept()) {               Writer out = new OutputStreamWriter(conne...