當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerSocketFactory類代碼示例

本文整理匯總了Java中javax.net.ServerSocketFactory的典型用法代碼示例。如果您正苦於以下問題:Java ServerSocketFactory類的具體用法?Java ServerSocketFactory怎麽用?Java ServerSocketFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ServerSocketFactory類屬於javax.net包,在下文中一共展示了ServerSocketFactory類的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: setUp

import javax.net.ServerSocketFactory; //導入依賴的package包/類
@Before public void setUp() throws Exception {
  // Sockets on some platforms can have large buffers that mean writes do not block when
  // required. These socket factories explicitly set the buffer sizes on sockets created.
  server = new MockWebServer();
  server.setServerSocketFactory(
      new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
        @Override protected ServerSocket configureServerSocket(
            ServerSocket serverSocket) throws IOException {
          serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return serverSocket;
        }
      });
  client = defaultClient().newBuilder()
      .socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
        @Override protected Socket configureSocket(Socket socket) throws IOException {
          socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
          socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return socket;
        }
      })
      .build();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:DisconnectTest.java

示例3: setUp

import javax.net.ServerSocketFactory; //導入依賴的package包/類
@Before public void setUp() throws Exception {
  // Sockets on some platforms can have large buffers that mean writes do not block when
  // required. These socket factories explicitly set the buffer sizes on sockets created.
  server = new MockWebServer();
  server.setServerSocketFactory(
      new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
        @Override
        protected ServerSocket configureServerSocket(ServerSocket serverSocket)
            throws IOException {
          serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return serverSocket;
        }
      });
  client = defaultClient().newBuilder()
      .socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
        @Override
        protected Socket configureSocket(Socket socket) throws IOException {
          socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
          socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return socket;
        }
      })
      .build();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:ThreadInterruptTest.java

示例4: HttpServer

import javax.net.ServerSocketFactory; //導入依賴的package包/類
HttpServer() throws Exception {
    super("HttpServer Thread");

    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(new FileInputStream(keystorefile), passphrase.toCharArray());
    KeyManagerFactory factory = KeyManagerFactory.getInstance("SunX509");
    factory.init(ks, passphrase.toCharArray());
    SSLContext ctx = SSLContext.getInstance("TLS");
    ctx.init(factory.getKeyManagers(), null, null);

    sslSocketFactory = ctx.getSocketFactory();

    // Create the server that the test wants to connect to via the proxy
    serverSocket = ServerSocketFactory.getDefault().createServerSocket();
    serverSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:B8025710.java

示例5: 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

示例6: 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

示例7: startProxy

import javax.net.ServerSocketFactory; //導入依賴的package包/類
static SocksProxy startProxy(Consumer<Socket> socketConsumer)
        throws IOException {
    Objects.requireNonNull(socketConsumer, "socketConsumer cannot be null");

    ServerSocket server
            = ServerSocketFactory.getDefault().createServerSocket(0);

    System.setProperty("socksProxyHost", "127.0.0.1");
    System.setProperty("socksProxyPort",
            String.valueOf(server.getLocalPort()));
    System.setProperty("socksProxyVersion", "4");

    SocksProxy proxy = new SocksProxy(server, socketConsumer);
    Thread proxyThread = new Thread(proxy, "Proxy");
    proxyThread.setDaemon(true);
    proxyThread.start();

    return proxy;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:SocksProxy.java

示例8: setUp

import javax.net.ServerSocketFactory; //導入依賴的package包/類
@Before public void setUp() throws Exception {
  // Sockets on some platforms can have large buffers that mean writes do not block when
  // required. These socket factories explicitly set the buffer sizes on sockets created.
  server = new MockWebServer();
  server.setServerSocketFactory(
      new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
        @Override protected ServerSocket configureServerSocket(
            ServerSocket serverSocket) throws IOException {
          serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return serverSocket;
        }
      });
  client = new OkHttpClient.Builder()
      .socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
        @Override protected Socket configureSocket(Socket socket) throws IOException {
          socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
          socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return socket;
        }
      })
      .build();
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:23,代碼來源:DisconnectTest.java

示例9: setUp

import javax.net.ServerSocketFactory; //導入依賴的package包/類
@Before public void setUp() throws Exception {
  // Sockets on some platforms can have large buffers that mean writes do not block when
  // required. These socket factories explicitly set the buffer sizes on sockets created.
  server = new MockWebServer();
  server.setServerSocketFactory(
      new DelegatingServerSocketFactory(ServerSocketFactory.getDefault()) {
        @Override
        protected ServerSocket configureServerSocket(ServerSocket serverSocket)
            throws IOException {
          serverSocket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return serverSocket;
        }
      });
  client = new OkHttpClient.Builder()
      .socketFactory(new DelegatingSocketFactory(SocketFactory.getDefault()) {
        @Override
        protected Socket configureSocket(Socket socket) throws IOException {
          socket.setSendBufferSize(SOCKET_BUFFER_SIZE);
          socket.setReceiveBufferSize(SOCKET_BUFFER_SIZE);
          return socket;
        }
      })
      .build();
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:25,代碼來源:ThreadInterruptTest.java

示例10: test_SSLContext_getServerSocketFactory

import javax.net.ServerSocketFactory; //導入依賴的package包/類
@Test
public void test_SSLContext_getServerSocketFactory() throws Exception {
    for (String protocol : StandardNames.SSL_CONTEXT_PROTOCOLS) {
        if (protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
            SSLContext.getInstance(protocol).getServerSocketFactory();
        } else {
            try {
                SSLContext.getInstance(protocol).getServerSocketFactory();
                fail();
            } catch (IllegalStateException expected) {
                // Ignored.
            }
        }

        SSLContext sslContext = SSLContext.getInstance(protocol);
        if (!protocol.equals(StandardNames.SSL_CONTEXT_PROTOCOLS_DEFAULT)) {
            sslContext.init(null, null, null);
        }
        ServerSocketFactory ssf = sslContext.getServerSocketFactory();
        assertNotNull(ssf);
        assertTrue(SSLServerSocketFactory.class.isAssignableFrom(ssf.getClass()));
    }
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:24,代碼來源:SSLContextTest.java

示例11: 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

示例12: testConnectTimeoutRead

import javax.net.ServerSocketFactory; //導入依賴的package包/類
@Test ( expected = ConnectionTimeoutException.class )
public void testConnectTimeoutRead () throws IOException {
    Set<Thread> threadsBefore = new HashSet<>(Thread.getAllStackTraces().keySet());
    try ( ServerSocket ss = ServerSocketFactory.getDefault().createServerSocket(0, -1, InetAddress.getLoopbackAddress()) ) {
        int port = ss.getLocalPort();
        InetAddress addr = ss.getInetAddress();

        long start = System.currentTimeMillis();
        CIFSContext ctx = lowConnectTimeout(getContext());
        try ( SmbResource f = new SmbFile(
            new URL("smb", addr.getHostAddress(), port, "/" + getTestShare() + "/connect.test", ctx.getUrlHandler()),
            ctx) ) {
            runConnectTimeoutTest(threadsBefore, start, ctx, f);
        }
    }
}
 
開發者ID:AgNO3,項目名稱:jcifs-ng,代碼行數:17,代碼來源:TimeoutTest.java

示例13: TestTCPServer

import javax.net.ServerSocketFactory; //導入依賴的package包/類
public TestTCPServer() {
	ServerSocket serverSocket = null;
	ExecutorService executor = null;
	try {
		serverSocket = ServerSocketFactory.getDefault().createServerSocket(0);
		System.setProperty("tcp.sink.test.port", Integer.toString(serverSocket.getLocalPort()));
		executor = Executors.newSingleThreadExecutor();
	}
	catch (IOException e) {
		e.printStackTrace();
	}
	this.serverSocket = serverSocket;
	this.executor = executor;
	this.decoder = new ByteArrayCrLfSerializer();
	executor.execute(this);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:17,代碼來源:TcpSinkTests.java

示例14: TestTCPServer

import javax.net.ServerSocketFactory; //導入依賴的package包/類
public TestTCPServer() {
	ServerSocket serverSocket = null;
	ExecutorService executor = null;
	try {
		serverSocket = ServerSocketFactory.getDefault().createServerSocket(0);
		System.setProperty("tcp.client.test.port", Integer.toString(serverSocket.getLocalPort()));
		executor = Executors.newSingleThreadExecutor();
	}
	catch (IOException e) {
		e.printStackTrace();
	}
	this.serverSocket = serverSocket;
	this.executor = executor;
	this.encoder = new ByteArrayCrLfSerializer();
	this.decoder = new ByteArrayCrLfSerializer();
	executor.execute(this);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-stream-app-starters,代碼行數:18,代碼來源:TcpClientTests.java

示例15: run

import javax.net.ServerSocketFactory; //導入依賴的package包/類
public void run() {
	try {
		logger.info("Collet Server start... port[{}]", port);
		serverSocket = ServerSocketFactory.getDefault().createServerSocket(port);
		while (!closed) {
			logger.info("Waiting to accept a new client.");
			Socket socket = serverSocket.accept();
			logger.info("Connected to client at " + socket.getRemoteSocketAddress());
			logger.info("Starting new socket node.");
			ColletSocketNode newSocketNode = new ColletSocketNode(this, socket);
			synchronized (socketNodeList) {
				socketNodeList.add(newSocketNode);
			}
			new Thread(newSocketNode).start();
		}
	} catch (Exception e) {
		if (closed) {
			logger.info("Exception in run method for a closed server. This is normal.");
		} else {
			logger.error("Unexpected failure in run method", e);
		}
	}
}
 
開發者ID:herowzz,項目名稱:SimLogMonitor,代碼行數:24,代碼來源:ColletSocketServer.java


注:本文中的javax.net.ServerSocketFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。