Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
import java.io.*;
import java.net.*;
class EchoServer 
{
    public static void main(String args[]) throws Exception
    {
        String clientstr;
	String fwdstr;
	ServerSocket ssock = new ServerSocket(5678);
		
	while(true) 
	{
	    Socket conn = ssock.accept();
			
	    BufferedReader inFromClient =new BufferedReader(new InputStreamReader(conn.getInputStream()));
	    DataOutputStream outToClient =new DataOutputStream(conn.getOutputStream());
			
            clientstr = inFromClient.readLine();
	    System.out.println("Input from the Client: "+clientstr);
	    fwdstr = clientstr+ '\n';
	    outToClient.writeBytes(fwdstr);
	}
    }
}



this is an echo server..i would like to know how could i make sure that multiple instances of this server is not running elsewhere??? please help..
Posted
Updated 10-Mar-10 6:51am
v2

I found this article on the net which may go some way to helping you with your query.

http://www.rbgrn.net/content/43-java-single-application-instance[^]
 
Share this answer
 
You need to learn singleton pattern aproach. You could find some articles by online search :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900