当前位置: 首页>>代码示例>>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;未经允许,请勿转载。