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


Java Socket.getLocalPort方法代码示例

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


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

示例1: doDirect

import java.net.Socket; //导入方法依赖的package包/类
private void doDirect() throws SocksException {
	try {
		log.debug("IP: {}_{}", remoteIP, remotePort);
		directSock = new Socket(remoteIP, remotePort);
		proxy.out = directSock.getOutputStream();
		proxy.in = directSock.getInputStream();
		proxy.proxySocket = directSock;
		localIP = directSock.getLocalAddress();
		localPort = directSock.getLocalPort();
	} catch (final IOException io_ex) {
		final int errCode = SocksProxyBase.SOCKS_DIRECT_FAILED;
		throw new SocksException(errCode, "Direct connect failed:", io_ex);
	}
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4j,代码行数:15,代码来源:SocksSocket.java

示例2: 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

示例3: ServerSessionManager

import java.net.Socket; //导入方法依赖的package包/类
public ServerSessionManager(Socket s) throws Exception {
    currentFile = local.getHomeDirectory();
    this.currentDir = currentFile.getAbsolutePath();
    osName = System.getProperty("os.name");
    userDir = System.getProperty("user.home");
    fileSeparator = System.getProperty("file.separator");
    update();
    try {
        this.controlSocket = s;
        this.remoteAddress = s.getInetAddress();
        this.remotePort = s.getPort();
        this.localPort = s.getLocalPort();
        initStreams();
        controlSocket.setSoTimeout(1000);
    } catch (Throwable t) {
        close("Cannot instantiate ControlChannel", t);
        throw new Exception(t);
    }
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:20,代码来源:ServerSessionManager.java

示例4: RecordedRequest

import java.net.Socket; //导入方法依赖的package包/类
public RecordedRequest(String requestLine, Headers headers, List<Integer> chunkSizes,
    long bodySize, Buffer body, int sequenceNumber, Socket socket) {
  this.requestLine = requestLine;
  this.headers = headers;
  this.chunkSizes = chunkSizes;
  this.bodySize = bodySize;
  this.body = body;
  this.sequenceNumber = sequenceNumber;
  this.tlsVersion = socket instanceof SSLSocket
      ? TlsVersion.forJavaName(((SSLSocket) socket).getSession().getProtocol())
      : null;

  if (requestLine != null) {
    int methodEnd = requestLine.indexOf(' ');
    int pathEnd = requestLine.indexOf(' ', methodEnd + 1);
    this.method = requestLine.substring(0, methodEnd);
    this.path = requestLine.substring(methodEnd + 1, pathEnd);

    String scheme = socket instanceof SSLSocket ? "https" : "http";
    String hostname = socket.getInetAddress().getHostName();
    int port = socket.getLocalPort();
    this.requestUrl = HttpUrl.parse(String.format("%s://%s:%s%s", scheme, hostname, port, path));
  } else {
    this.requestUrl = null;
    this.method = null;
    this.path = null;
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:RecordedRequest.java

示例5: GUIControlChannel

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Try to connect to a remote FDT instance
 *
 * @param inetAddress
 * @param port
 * @param notifier
 * @throws Exception
 */
public GUIControlChannel(InetAddress inetAddress, int port, GUIControlChannelNotifier notifier) throws Exception {
    try {
        this.notifier = notifier;

        controlSocket = new Socket();
        controlSocket.connect(new InetSocketAddress(inetAddress, port), CONNECT_TIMEOUT);

        this.remoteAddress = inetAddress;
        this.remotePort = port;
        this.localPort = controlSocket.getLocalPort();

        controlSocket.setTcpNoDelay(true);

        //only the first octet will be interpreted by the AcceptTask at the other end
        controlSocket.getOutputStream().write(new byte[]{3});

        //from now on only CtrlMsg will be sent
        initStreams();
        controlSocket.setSoTimeout(1000);

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

示例6: 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

示例7: AgentWorker

import java.net.Socket; //导入方法依赖的package包/类
public AgentWorker(NbJShellAgent agent, Socket controlSocket) {
    this.agent = agent;
    this.socket = controlSocket;
    this.socketPort = controlSocket.getLocalPort();
    setup();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:AgentWorker.java

示例8: 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

示例9: getLocalPort

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

示例10: getSimulatorConnection

import java.net.Socket; //导入方法依赖的package包/类
/**
 * return the connection for the given ClientSocket
 * 
 * @param clientSocket
 * @return the connection
 */
public ELM327SimulatorConnection getSimulatorConnection(Socket clientSocket) {
  int clientPort = clientSocket.getLocalPort();
  ELM327SimulatorConnection con = simulatorConnectionsByPort.get(clientPort);
  return con;
}
 
开发者ID:BITPlan,项目名称:can4eve,代码行数:12,代码来源:ElmSimulator.java


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