本文整理汇总了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);
}
}
示例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();
}
示例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();
}
示例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));
}
示例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");
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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()));
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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);
}
}
}