防止同一服务器的多个实例 [英] prevent multiple instances of same server

查看:81
本文介绍了防止同一服务器的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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..

推荐答案

我在网上发现了这篇文章,这可能可以帮助您进行查询.

> http://www.rbgrn.net/content/43-java-single-application-instance [^ ]
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[^]


您需要学习单例模式的方法.您可以通过在线搜索找到一些文章:)
You need to learn singleton pattern aproach. You could find some articles by online search :)


这篇关于防止同一服务器的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆