本文整理汇总了Java中javax.net.ServerSocketFactory.getDefault方法的典型用法代码示例。如果您正苦于以下问题:Java ServerSocketFactory.getDefault方法的具体用法?Java ServerSocketFactory.getDefault怎么用?Java ServerSocketFactory.getDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ServerSocketFactory
的用法示例。
在下文中一共展示了ServerSocketFactory.getDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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();
}
}
}
示例4: exportService
import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
protected void exportService()
throws Exception {
// export
// create a stream server if needed
if (streamServer==null) {
// make sure we have a factory
if (serverSocketFactory==null) {
serverSocketFactory = ServerSocketFactory.getDefault();
}
// create server socket
ServerSocket serverSocket = serverSocketFactory
.createServerSocket(port, backlog, InetAddress.getByName(hostName));
// create the stream server
streamServer = new StreamServer(getJsonRpcServer(), maxThreads, serverSocket);
streamServer.setMaxClientErrors(maxClientErrors);
}
// start it
streamServer.start();
}
示例5: exportService
import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void exportService()
throws Exception {
// create a stream server if needed
if (streamServer==null) {
// make sure we have a factory
if (serverSocketFactory==null) {
serverSocketFactory = ServerSocketFactory.getDefault();
}
// create server socket
ServerSocket serverSocket = serverSocketFactory
.createServerSocket(port, backlog, InetAddress.getByName(hostName));
// create the stream server
streamServer = new StreamServer(getJsonRpcServer(), maxThreads, serverSocket);
streamServer.setMaxClientErrors(maxClientErrors);
}
// start it
streamServer.start();
}
示例6: 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);
}
}
示例7: 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;
}
}
示例8: getServerSocketFactory
import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
* Get the server socket factory from the underlying SSL context.
* @return Server socket factory
*/
public ServerSocketFactory getServerSocketFactory() {
if (ConditionalCompilationControls.TESTHARNESS) {
if (ConditionalCompilationControls.cleartext)
return ServerSocketFactory.getDefault();
}
return context.getServerSocketFactory();
}
示例9: 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;
}
}
示例10: 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("Visualization interface server socket succesfully created (port " + this.port + ")");
} catch (IOException e) {
System.out.println("Could not Connect to Visualization interface server");
throw e;
}
}
示例11: getSocketFactory
import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
private synchronized ServerSocketFactory getSocketFactory()
{
if (socketFactory == null)
socketFactory = ServerSocketFactory.getDefault();
return socketFactory;
}
示例12: MonitoringServer
import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
* Return statistics about the GSN server, faking an HTTP server for retro-compatibility
*
* the protocol is similar to the carbon protocol used by Graphite, except the timestamp
* http://matt.aimonetti.net/posts/2013/06/26/practical-guide-to-graphite-monitoring/
*/
public MonitoringServer(int port) {
super("Monitoring Server");
try {
ServerSocketFactory serverSocketFactory = ServerSocketFactory.getDefault();
socket = serverSocketFactory.createServerSocket(port);
socket.setSoTimeout(1000);
}catch(Exception e){
logger.error("unable to open socket for monitoring",e);
}
}
示例13: main
import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
String serverName = "Deep Thought";
String configFile = "config";
ServerSocketFactory serverSockets = ServerSocketFactory.getDefault();
SocketIOWrapperFactory socketWrappers = SocketIOWrapperFactory.getDefault();
WebServer server = WebServer.createWebServer(serverName, configFile, serverSockets, socketWrappers);
GUIWebServer gui = new GUIWebServer(server);
gui.start();
try {
gui.awaitTermination();
} catch (Exception e) {
}
}
示例14: exportService
import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void exportService() throws Exception {
if (streamServer == null) {
if (serverSocketFactory == null) {
serverSocketFactory = ServerSocketFactory.getDefault();
}
ServerSocket serverSocket = serverSocketFactory.createServerSocket(port, backlog, InetAddress.getByName(hostName));
streamServer = new StreamServer(getJsonRpcServer(), maxThreads, serverSocket);
streamServer.setMaxClientErrors(maxClientErrors);
}
streamServer.start();
}
示例15: exportService
import javax.net.ServerSocketFactory; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void exportService() throws Exception {
if (streamServer == null) {
if (serverSocketFactory == null) {
serverSocketFactory = ServerSocketFactory.getDefault();
}
ServerSocket serverSocket =
serverSocketFactory.createServerSocket(port, backlog, InetAddress.getByName(hostName));
streamServer = new StreamServer(getJsonRpcServer(), maxThreads, serverSocket);
streamServer.setMaxClientErrors(maxClientErrors);
}
streamServer.start();
}