当前位置: 首页>>代码示例>>Java>>正文


Java ServerSocketFactory.createServerSocket方法代码示例

本文整理汇总了Java中javax.net.ServerSocketFactory.createServerSocket方法的典型用法代码示例。如果您正苦于以下问题:Java ServerSocketFactory.createServerSocket方法的具体用法?Java ServerSocketFactory.createServerSocket怎么用?Java ServerSocketFactory.createServerSocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.net.ServerSocketFactory的用法示例。


在下文中一共展示了ServerSocketFactory.createServerSocket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // reserve the security properties
    String reservedSSFacProvider =
        Security.getProperty("ssl.ServerSocketFactory.provider");

    try {
        Security.setProperty("ssl.ServerSocketFactory.provider", "oops");
        ServerSocketFactory ssocketFactory =
                    SSLServerSocketFactory.getDefault();
        SSLServerSocket sslServerSocket =
                    (SSLServerSocket)ssocketFactory.createServerSocket();
    } catch (Exception e) {
        if (!(e.getCause() instanceof ClassNotFoundException)) {
            throw e;
        }
        // get the expected exception
    } finally {
        // restore the security properties
        if (reservedSSFacProvider == null) {
            reservedSSFacProvider = "";
        }
        Security.setProperty("ssl.ServerSocketFactory.provider",
                                                reservedSSFacProvider);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:DefaultSSLServSocketFac.java

示例2: main

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  ServerSocketFactory ssf = SSLServerSocketFactory.getDefault();
  ServerSocket ss = ssf.createServerSocket(Integer.parseInt(args[0]));

  System.out.println("Ready...");


  SSLSimpleServer server = new SSLSimpleServer(ss);

  new Thread(server).start();
  try {
    Thread.sleep(200 * 1000);
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
  System.out.println("Stopping Server");

}
 
开发者ID:jeffreyshen19,项目名称:Virtual-IoT-Server,代码行数:19,代码来源:SSLSimpleServer.java

示例3: initSecure

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
final ServerSocket initSecure(int port) throws Exception {
    ServerSocketFactory fac;
    if (sslContext != null) {
        fac = sslContext.getServerSocketFactory();
    } else {
        fac = SSLServerSocketFactory.getDefault();
    }
    SSLServerSocket se = (SSLServerSocket) fac.createServerSocket(port);
    SSLParameters sslp = se.getSSLParameters();
    sslp.setApplicationProtocols(new String[]{"h2"});
    se.setSSLParameters(sslp);
    se.setEnabledCipherSuites(se.getSupportedCipherSuites());
    se.setEnabledProtocols(se.getSupportedProtocols());
    // other initialisation here
    return se;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Http2TestServer.java

示例4: initialize

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
 * Initialize this socket connection. This includes
 * connecting to the host (or listening for it).
 *
 * @throws TransportException if a transport-related error occurs
 */
public void initialize ()
  throws TransportException
{
  try
    {
      if (_server)
        {
          // Get a server socket
          ServerSocketFactory ssf = ServerSocketFactory.getDefault ();
          ServerSocket ss = ssf.createServerSocket (_port, 1);
          _socket = ss.accept ();
        }
      else
        {
          // Get a client socket (the factory will connect it)
          SocketFactory sf = SocketFactory.getDefault ();
          _socket = sf.createSocket (_host, _port);
        }
    }
  catch (IOException ioe)
    {
      // This will grab UnknownHostException, too.
      throw new TransportException (ioe);
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:32,代码来源:SocketTransport.java

示例5: initialize

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
  * Initialize this socket connection. This includes
  * connecting to the host (or listening for it).
  *
  * @throws TransportException if a transport-related error occurs
  */
 public void initialize ()
   throws TransportException
 {
   try
     {
if (_server)
  {
    // Get a server socket
    ServerSocketFactory ssf = ServerSocketFactory.getDefault ();
    ServerSocket ss = ssf.createServerSocket (_port, 1);
    _socket = ss.accept ();
  }
else
  {
    // Get a client socket (the factory will connect it)
    SocketFactory sf = SocketFactory.getDefault ();
    _socket = sf.createSocket (_host, _port);
  }
     }
   catch (IOException ioe)
     {
// This will grab UnknownHostException, too.
throw new TransportException (ioe);
     }
 }
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:32,代码来源:SocketTransport.java

示例6: createServerSocket

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
 * Creates a new {@link ServerSocket} bound to a random unused port.
 * @param socketFactory socket factory that will be used to create the 
 *    socket
 * @return socket
 * @throws IOException
 */
public static ServerSocket createServerSocket(
    ServerSocketFactory socketFactory) throws IOException {
  ServerSocket socket = null;
  int retries = 10;
  while (retries-- > 0 && socket == null) {
    int port = (int)((65536 - 1024) * Math.random()) + 1024;
    try {
      socket = socketFactory.createServerSocket(port);
    }
    catch (BindException ex) {
      // try again with different port
    }
  }
  if (socket == null) {
    throw new BindException("cannot find an unused port to bind");
  }
  return socket;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:26,代码来源:ServerSocketUtil.java

示例7: main

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  ServerSocketFactory socketFactory = ServerSocketFactory.getDefault();
  ServerSocket serverSocket = null;
  try {
    serverSocket = socketFactory.createServerSocket(SERVER_PORT);

    listenAndRespond(serverSocket);

  } catch (IOException e) {
    System.out.printf("Socket Failure: %s", e.getMessage());
  } finally {
    if (serverSocket != null) {
      serverSocket.close();
    }
  }
}
 
开发者ID:TripwireInc,项目名称:interview-take-home-test,代码行数:17,代码来源:Server.java

示例8: createServerSocket

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
protected ServerSocket createServerSocket() throws IOException {
	ServerSocket newServerSocket = null;
	
	ServerSocketFactory factory = getServerSocketFactory();
	
	if (this.syslogServerConfig.getHost() != null) {
		InetAddress inetAddress = InetAddress.getByName(this.syslogServerConfig.getHost());
			
		newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort(),this.tcpNetSyslogServerConfig.getBacklog(),inetAddress); 
			
	} else {
		if (this.tcpNetSyslogServerConfig.getBacklog() < 1) {
			newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort());
			
		} else {
			newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort(),this.tcpNetSyslogServerConfig.getBacklog());				
		}
	}
	
	return newServerSocket;
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:22,代码来源:TCPNetSyslogServer.java

示例9: createServerSocket

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
protected ServerSocket createServerSocket() throws IOException {
    ServerSocket newServerSocket = null;

    ServerSocketFactory factory = getServerSocketFactory();

    if (this.syslogServerConfig.getHost() != null) {
        InetAddress inetAddress = InetAddress.getByName(this.syslogServerConfig.getHost());

        newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort(), this.tcpNetSyslogServerConfig.getBacklog(), inetAddress);

    } else {
        if (this.tcpNetSyslogServerConfig.getBacklog() < 1) {
            newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort());

        } else {
            newServerSocket = factory.createServerSocket(this.syslogServerConfig.getPort(), this.tcpNetSyslogServerConfig.getBacklog());
        }
    }

    return newServerSocket;
}
 
开发者ID:graylog-labs,项目名称:syslog4j-graylog2,代码行数:22,代码来源:TCPNetSyslogServer.java

示例10: start

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
@Override
public void start() throws IOException {
	if (log.isDebugEnabled()) log.debug(HelperLog.methodStart());
	
	setRunning(true);

	final ServerSocketFactory sslFactory = SSLServerSocketFactory.getDefault();
	final ServerSocket serverSocket = sslFactory.createServerSocket(getPort());

	if (0 < getTimeout()) {
		serverSocket.setSoTimeout(getTimeout());
	}

	setServerSocket(serverSocket);

	setThread(new Thread(this));
	getThread().start();
	
	if (log.isDebugEnabled()) log.debug(HelperLog.methodExit());
}
 
开发者ID:slaubenberger,项目名称:wichtel,代码行数:21,代码来源:ServerSSLAbstract.java

示例11: runServer

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
private static void runServer(int port, LocalSunXacml pdp, int threads) {
	Executor clientExec = Executors.newFixedThreadPool(threads);
	ServerSocketFactory sockFac = ServerSocketFactory.getDefault();


	try {
		ServerSocket sock = sockFac.createServerSocket(port);
		while (true) {
			Socket clientSock = sock.accept();
			Runnable cmd = new HandleXacmlRequest(clientSock, pdp);
			System.out.println(nameDate() + "new client " + clientSock.getInetAddress());
			clientExec.execute(cmd);
		}
	} catch (IOException e) {
		System.err.println(nameDate() + e.toString());
		System.exit(1);
	}
}
 
开发者ID:trustathsh,项目名称:irond,代码行数:19,代码来源:RemotePDP.java

示例12: createServerSocket

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
 * Create the right kind of server socket
 */

private ServerSocket createServerSocket()
	throws IOException
{
	if (hostAddress == null)
		hostAddress = InetAddress.getByName(hostArg);
	// Make a list of valid
	// InetAddresses for NetworkServerControl
	// admin commands.
	buildLocalAddressList(hostAddress);
										
	// Create the right kind of socket
	switch (getSSLMode()) {
	case SSL_OFF:
	default:
		ServerSocketFactory sf =
			ServerSocketFactory.getDefault();
		return sf.createServerSocket(portNumber
									 ,0,
									 hostAddress);
	case SSL_BASIC:
		SSLServerSocketFactory ssf =
			(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
		return (SSLServerSocket)ssf.createServerSocket(portNumber,
													   0,
													   hostAddress);
	case SSL_PEER_AUTHENTICATION:
		SSLServerSocketFactory ssf2 =
			(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
		SSLServerSocket sss2= 
			(SSLServerSocket)ssf2.createServerSocket(portNumber,
													 0,
													 hostAddress);
		sss2.setNeedClientAuth(true);
		return sss2;
	}
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:41,代码来源:NetworkServerControlImpl.java

示例13: createServerSocket

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
private ServerSocket createServerSocket(int port, ServerSocketFactory ssf, String bindIP) throws IOException {
	ServerSocket ss = ssf.createServerSocket();
	if (_bufferSize > 0) {
		ss.setReceiveBufferSize(_bufferSize);	
	}
	if (bindIP == null) {
		ss.bind(new InetSocketAddress(port),1);
	} else {
		ss.bind(new InetSocketAddress(bindIP,port),1);
	}
	return ss;
}
 
开发者ID:drftpd-ng,项目名称:drftpd3,代码行数:13,代码来源:PortRange.java

示例14: main

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    try {
        Security.setProperty("ssl.ServerSocketFactory.provider", "oops");
        ServerSocketFactory ssocketFactory =
                    SSLServerSocketFactory.getDefault();
        SSLServerSocket sslServerSocket =
                    (SSLServerSocket)ssocketFactory.createServerSocket();
    } catch (Exception e) {
        if (!(e.getCause() instanceof ClassNotFoundException)) {
            throw e;
        }
        // get the expected exception
    }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:15,代码来源:DefaultSSLServSocketFac.java

示例15: ConnectServer

import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
* Starts the listening server on the defined port.
* @param port the port for the communication with state control
* @throws IOException
*/
   private void ConnectServer(int port) throws IOException{
   	stopServer();
       try {
       	ServerSocketFactory serverSocketFactory = ServerSocketFactory.getDefault();
       	openIGTServer = serverSocketFactory.createServerSocket(this.port);
       	openIGTServer.setReuseAddress(true);
       	System.out.println("State machine interface server Socket succesfully created (port " + this.port + ")");
       } catch (IOException e) {
       	System.out.println("Could not Connect to port :" + this.port + ")");
               throw e;
       }
   }
 
开发者ID:tauscherSw,项目名称:LWROpenIGTIF,代码行数:18,代码来源:LWRStateMachineInterface.java


注:本文中的javax.net.ServerSocketFactory.createServerSocket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。