Demo entry 6311120

TCPServer.java

   

Submitted by anonymous on Oct 24, 2016 at 16:10
Language: Java. Code size: 1.3 kB.

/**
 * @Author: mdrhri-6
 * @Date:   2016-10-24T00:13:03+02:00
* @Last modified by:   mdrhri-6
* @Last modified time: 2016-10-24T16:09:36+02:00
 */


import java.net.ServerSocket;
import java.net.Socket;
import java.util.Hashtable;

/**
 * Created by Rafiul Sabbir on 24/10/16.
 */

class TCPServer
{
    //static ServerSocket welcomeSocket;
    static Integer port = 8080;

    static Hashtable<String, Object>  storage = new Hashtable<String, Object>();

    public static void main(String argv[]) throws Exception
    {
    	ServerSocket welcomeSocket = new ServerSocket(port);
        System.out.println("TCP Server created at port " + port);

        while(true)
        {
            Socket connectionSocket = welcomeSocket.accept();
            System.out.println(Thread.currentThread().getName() +":"+connectionSocket.toString());

            String ipAddress = connectionSocket.getInetAddress().getHostAddress();
            Integer portNumber = connectionSocket.getPort();

            storage.put( ipAddress + " - " + portNumber, connectionSocket);

            TCPHandler handler=new TCPHandler(connectionSocket, storage, ipAddress, portNumber);
            handler.start();
        }

    }
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).