当前位置: 首页>>代码示例>>Java>>正文


Java Socket.getPort方法代码示例

本文整理汇总了Java中java.net.Socket.getPort方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.getPort方法的具体用法?Java Socket.getPort怎么用?Java Socket.getPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.Socket的用法示例。


在下文中一共展示了Socket.getPort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MMOConnection

import java.net.Socket; //导入方法依赖的package包/类
public MMOConnection(SelectorThread<T> selectorThread, Socket socket, SelectionKey key, boolean tcpNoDelay)
{
	_selectorThread = selectorThread;
	_socket = socket;
	_address = socket.getInetAddress();
	_readableByteChannel = socket.getChannel();
	_writableByteChannel = socket.getChannel();
	_port = socket.getPort();
	_selectionKey = key;
	
	_sendQueue = new NioNetStackList<>();
	
	try
	{
		_socket.setTcpNoDelay(tcpNoDelay);
	}
	catch (SocketException e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:22,代码来源:MMOConnection.java

示例2: start

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Create a server with the specified port, listen backlog, and local IP
 * address to bind to. The localIP argument can be used on a multi-homed
 * host for a ServerSocket that will only accept connect requests to one of
 * its addresses. If localIP is null, it will default accepting connections
 * on any/all local addresses. The port must be between 0 and 65535,
 * inclusive. <br>
 * This methods blocks.
 */
public void start(final int port, final int backlog,
		final InetAddress localIP) {
	try {
		ss = new ServerSocket(port, backlog, localIP);
		final String address = ss.getInetAddress().getHostAddress();
		final int localPort = ss.getLocalPort();
		log.info("Starting SOCKS Proxy on: {}:{}", address, localPort);

		while (true) {
			final Socket s = ss.accept();
			final String hostName = s.getInetAddress().getHostName();
			final int port2 = s.getPort();
			log.info("Accepted from:{}:{}", hostName, port2);

			final ProxyServer ps = new ProxyServer(auth, s);
			(new Thread(ps)).start();
		}
	} catch (final IOException ioe) {
		ioe.printStackTrace();
	} finally {
	}
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4Android,代码行数:32,代码来源:ProxyServer.java

示例3: ControlChannel

import java.net.Socket; //导入方法依赖的package包/类
/**
 * A remote peer connected to FDT
 *
 * @param s - the socket
 * @throws Exception - if anything goes wrong in intialization
 */
public ControlChannel(Socket s, ControlChannelNotifier notifier) throws Exception {
    try {
        this.controlSocket = s;

        this.remoteAddress = s.getInetAddress();
        this.remotePort = s.getPort();
        this.localPort = s.getLocalPort();

        this.notifier = notifier;

        initStreams();
        controlSocket.setTcpNoDelay(true);
        controlSocket.setSoTimeout(1000);

    } catch (Throwable t) {
        close("Cannot instantiate ControlChannel", t);
        throw new Exception(t);
    }
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:26,代码来源:ControlChannel.java

示例4: MMOConnection

import java.net.Socket; //导入方法依赖的package包/类
public MMOConnection(final SelectorThread<T> selectorThread, final Socket socket, final SelectionKey key)
{
    _selectorThread = selectorThread;
    _socket = socket;
    _address = socket.getInetAddress();
    _readableByteChannel = socket.getChannel();
    _writableByteChannel = socket.getChannel();
    _port = socket.getPort();
    _selectionKey = key;

    _sendQueue = new NioNetStackList<SendablePacket<T>>();
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:13,代码来源:MMOConnection.java

示例5: MinicraftServerThread

import java.net.Socket; //导入方法依赖的package包/类
public MinicraftServerThread(Socket socket, MinicraftServer serverInstance) {
	super("MinicraftServerThread", socket);
	
	this.serverInstance = serverInstance;
	if(serverInstance.isFull()) {
		sendError("server at max capacity.");
		super.endConnection();
		return;
	}
	
	client = new RemotePlayer(null, false, socket.getInetAddress(), socket.getPort());
	
	// username is set later
	
	packetTypesToKeep.addAll(InputType.tileUpdates);
	packetTypesToKeep.addAll(InputType.entityUpdates);
	
	gameTimers = new ArrayList<>();
	
	Timer t = new Timer("ClientPing");
	t.schedule((new MyTask() {
		public void run() { MinicraftServerThread.this.ping(); }
	}), 1000, PING_INTERVAL*1000);
	gameTimers.add(t);
	
	start();
}
 
开发者ID:chrisj42,项目名称:minicraft-plus-revived,代码行数:28,代码来源:MinicraftServerThread.java

示例6: chooseClientAlias

import java.net.Socket; //导入方法依赖的package包/类
@Override
public String chooseClientAlias(final String[] keyTypes, final Principal[] issuers, final Socket socket) {
    final Key key = new Key(socket.getInetAddress().getHostName(), socket.getPort(), issuers);
    final String alias = this.find(key);
    if(alias != null) {
        return alias;
    }
    final String s = super.chooseClientAlias(keyTypes, issuers, socket);
    if(null == s) {
        return null;
    }
    return this.save(key, s);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:14,代码来源:KeychainX509KeyManager.java

示例7: addNewUserConnection

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Add a new user connection.  That is a new connection to the server
 * that has not yet logged in as a player.
 *
 * @param socket The client {@code Socket} the connection arrives on.
 * @exception IOException if the socket was already broken.
 */
public void addNewUserConnection(Socket socket) throws IOException {
    final String name = socket.getInetAddress() + ":" + socket.getPort();
    Connection c = new Connection(socket, FreeCol.SERVER_THREAD + name)
        .setMessageHandler(this.userConnectionHandler);
    getServer().addConnection(c);
    // Short delay here improves reliability
    Utils.delay(100, "New connection delay interrupted");
    c.send(new GameStateMessage(this.serverState));
    if (this.serverState == ServerState.IN_GAME) {
        c.send(new VacantPlayersMessage().setVacantPlayers(getGame()));
    }
    logger.info("Client connected from " + name);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:21,代码来源:FreeColServer.java

示例8: XDRTcpSocket

import java.net.Socket; //导入方法依赖的package包/类
public XDRTcpSocket(Socket s) throws IOException {
      super("XDRTcpSocket for [ " + s.getInetAddress() + ":" + s.getPort() + " ] ", new XDROutputStream(s.getOutputStream()), new XDRInputStream(s.getInputStream()));
      this.rawSocket = s;
      closed = false;
/*this.mode = mode;
this.auth = auth;*/
  }
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:8,代码来源:XDRTcpSocket.java

示例9: InterposeSocket

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Construct a socket that interposes on a socket to match and replace.
 * @param socket the underlying socket
 * @param triggerBytes array of bytes to enable matching
 * @param matchBytes the bytes that must match
 * @param replaceBytes the replacement bytes
 */
public InterposeSocket(Socket socket, byte[]
        triggerBytes, byte[] matchBytes, byte[] replaceBytes) {
    this.socket = socket;
    this.triggerBytes = Objects.requireNonNull(triggerBytes, "triggerBytes");
    this.matchBytes = Objects.requireNonNull(matchBytes, "matchBytes");
    this.replaceBytes = Objects.requireNonNull(replaceBytes, "replaceBytes");
    this.inLogStream = new ByteArrayOutputStream();
    this.outLogStream = new ByteArrayOutputStream();
    this.name = "IS" + ++num + "::"
            + Thread.currentThread().getName() + ": "
            + socket.getLocalPort() + " <  " + socket.getPort();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TestSocketFactory.java

示例10: Pump

import java.net.Socket; //导入方法依赖的package包/类
public Pump(Socket source, Socket dest) {
    super("SocketProxy-DataTransfer-" + source.getPort() + ":" + dest.getPort());
    src = source;
    destination = dest;
    pause.set(new CountDownLatch(0));
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:7,代码来源:SocketProxy.java

示例11: connect

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Like {@link NetUtils#connect(Socket, SocketAddress, int)} but
 * also takes a local address and port to bind the socket to. 
 * 
 * @param socket
 * @param endpoint the remote address
 * @param localAddr the local address to bind the socket to
 * @param timeout timeout in milliseconds
 */
public static void connect(Socket socket, 
                           SocketAddress endpoint,
                           SocketAddress localAddr,
                           int timeout) throws IOException {
  if (socket == null || endpoint == null || timeout < 0) {
    throw new IllegalArgumentException("Illegal argument for connect()");
  }
  
  SocketChannel ch = socket.getChannel();
  
  if (localAddr != null) {
    Class localClass = localAddr.getClass();
    Class remoteClass = endpoint.getClass();
    Preconditions.checkArgument(localClass.equals(remoteClass),
        "Local address %s must be of same family as remote address %s.",
        localAddr, endpoint);
    socket.bind(localAddr);
  }

  try {
    if (ch == null) {
      // let the default implementation handle it.
      socket.connect(endpoint, timeout);
    } else {
      SocketIOWithTimeout.connect(ch, endpoint, timeout);
    }
  } catch (SocketTimeoutException ste) {
    throw new ConnectTimeoutException(ste.getMessage());
  }

  // There is a very rare case allowed by the TCP specification, such that
  // if we are trying to connect to an endpoint on the local machine,
  // and we end up choosing an ephemeral port equal to the destination port,
  // we will actually end up getting connected to ourself (ie any data we
  // send just comes right back). This is only possible if the target
  // daemon is down, so we'll treat it like connection refused.
  if (socket.getLocalPort() == socket.getPort() &&
      socket.getLocalAddress().equals(socket.getInetAddress())) {
    LOG.info("Detected a loopback TCP socket, disconnecting it");
    socket.close();
    throw new ConnectException(
      "Localhost targeted connection resulted in a loopback. " +
      "No daemon is listening on the target port.");
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:55,代码来源:NetUtils.java

示例12: getHostPort

import java.net.Socket; //导入方法依赖的package包/类
public static String getHostPort(Socket s)
{
	String h = s.getInetAddress().getHostAddress().toString();
	int port = s.getPort();
	return h + ":" + port;
}
 
开发者ID:D4RK0V3RL0RD676,项目名称:apcs_final,代码行数:7,代码来源:LANUtils.java

示例13: getRemotePort

import java.net.Socket; //导入方法依赖的package包/类
@Override
public int getRemotePort() {
    final Socket socket = this.socketHolder.get();
    return socket != null ? socket.getPort() : -1;
}
 
开发者ID:kalikov,项目名称:lighthouse,代码行数:6,代码来源:BHttpConnectionBase.java

示例14: createHandle

import java.net.Socket; //导入方法依赖的package包/类
private String createHandle(Socket socket) {
	return "Socket:" + socket.getInetAddress().toString() + ":" + socket.getPort() + "/" + (++socketIdx);
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:4,代码来源:SocketExtension.java

示例15: ClientConnection

import java.net.Socket; //导入方法依赖的package包/类
public ClientConnection(Server serv, Socket s) {
    this.serv = serv;
    this.s = s;
    byte[] addr = s.getInetAddress().getAddress();
    chId = (addr[0] << 48 | addr[1] << 32 | addr[2] << 24 | addr[3] << 16) + s.getPort(); //generate unique chId from client's IP and port
}
 
开发者ID:lucas-dolsan,项目名称:tcc-rpg,代码行数:7,代码来源:ClientConnection.java


注:本文中的java.net.Socket.getPort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。