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