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


Java InetSocketAddress类代码示例

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


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

示例1: getProxy

import java.net.InetSocketAddress; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> ProtocolProxy<T> getProxy(
    Class<T> protocol, long clientVersion, InetSocketAddress addr,
    UserGroupInformation ticket, Configuration conf, SocketFactory factory,
    int rpcTimeout, RetryPolicy connectionRetryPolicy,
    AtomicBoolean fallbackToSimpleAuth) throws IOException {
  T proxy = (T) Proxy.newProxyInstance(protocol.getClassLoader(),
      new Class[] { protocol }, new StoppedInvocationHandler());
  return new ProtocolProxy<T>(protocol, proxy, false);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:12,代码来源:TestRPC.java

示例2: getProxy

import java.net.InetSocketAddress; //导入依赖的package包/类
/** Construct a client-side proxy object that implements the named protocol,
 * talking to a server at the named address. */
public static <T> T  getProxy(
    Class<T> protocol,
    long clientVersion, InetSocketAddress addr,
    Configuration conf, SocketFactory factory, int rpcTimeout) throws IOException {

     T proxy =
	   (T) Proxy.newProxyInstance(
          protocol.getClassLoader(), new Class[] { protocol },
          new Invoker(protocol, addr, conf, factory, rpcTimeout));

  return proxy;
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:15,代码来源:RPC.java

示例3: a

import java.net.InetSocketAddress; //导入依赖的package包/类
private static HttpURLConnection a(Context context, String str) {
    try {
        URL url = new URL(str);
        if (context.getPackageManager().checkPermission(z[43], context.getPackageName()) == 0) {
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService(z[44])).getActiveNetworkInfo();
            if (!(activeNetworkInfo == null || activeNetworkInfo.getType() == 1)) {
                String extraInfo = activeNetworkInfo.getExtraInfo();
                if (extraInfo != null && (extraInfo.equals(z[40]) || extraInfo.equals(z[41]) || extraInfo.equals(z[42]))) {
                    return (HttpURLConnection) url.openConnection(new Proxy(Type.HTTP, new InetSocketAddress(z[45], 80)));
                }
            }
        }
        return (HttpURLConnection) url.openConnection();
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e2) {
        e2.printStackTrace();
        return null;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:p.java

示例4: setUp

import java.net.InetSocketAddress; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
    DelayedTransactionId dti1 = new DelayedTransactionId(new byte[]{13, 14}, new InetSocketAddress(5683));
    DelayedTransactionId dti2 = new DelayedTransactionId(new byte[]{13, 14}, new InetSocketAddress(5683));
    dti1.equals(dti2);

    assertEquals(dti1.hashCode(), dti2.hashCode());
    assertEquals(dti1, dti2);

    server = CoapServer.builder().transport(InMemoryCoapTransport.create())
            .timeout(new SingleTimeout(1000))
            .build();
    server.addRequestHandler("/temp", new ReadOnlyCoapResource("23 C"));

    server.addRequestHandler("/seperate", new CoapResourceSeparateRespImpl("test-content"));
    server.start();
    serverAddr = InMemoryCoapTransport.createAddress(server.getLocalSocketAddress().getPort());
}
 
开发者ID:ARMmbed,项目名称:java-coap,代码行数:19,代码来源:ClientServerNONTest.java

示例5: findLeader

import java.net.InetSocketAddress; //导入依赖的package包/类
/**
 * Returns the address of the node we think is the leader.
 */
protected InetSocketAddress findLeader() {
    InetSocketAddress addr = null;
    // Find the leader by id
    Vote current = self.getCurrentVote();
    for (QuorumServer s : self.getView().values()) {
        if (s.id == current.getId()) {
            // Ensure we have the leader's correct IP address before
            // attempting to connect.
            s.recreateSocketAddresses();
            addr = s.addr;
            break;
        }
    }
    if (addr == null) {
        LOG.warn("Couldn't find the leader with id = "
                + current.getId());
    }
    return addr;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:23,代码来源:Learner.java

示例6: main

import java.net.InetSocketAddress; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
    InetAddress iaddr = InetAddress.getLocalHost();

    try ( ServerSocket ss = new ServerSocket(0);
          Socket s1 = new Socket(iaddr, ss.getLocalPort());
          Socket s2 = ss.accept() ) {

        test(s1, s2, "Testing NET");
    }

    // check the NIO socket adapter
    try (ServerSocketChannel sc = ServerSocketChannel.open().bind(null);
         SocketChannel s1 = SocketChannel.open(
                 new InetSocketAddress(iaddr, sc.socket().getLocalPort()));
         SocketChannel s2 = sc.accept() ) {

        test(s1.socket(), s2.socket(), "Testing NIO");
    }

    if (failed) {
        throw new RuntimeException("Failed: check output");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ShutdownInput.java

示例7: getAvailablePort

import java.net.InetSocketAddress; //导入依赖的package包/类
private int getAvailablePort(int fromPort, int toPort) {
	if (toPort <= fromPort) return fromPort;
	int count = 50;
	int step = (toPort - fromPort) / count;
	while (count > 0) {
		int port = fromPort + (50-count) * step + random.nextInt(step);
		try {
		    ServerSocket s = new ServerSocket();
		    s.bind(new InetSocketAddress("localhost", port));
		    s.close();			    
		} catch (IOException ex) {
			--count;
		    continue;
		}
		return port;
	}
	return random.nextInt((toPort-fromPort)) + fromPort;
	
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:20,代码来源:UT2004TCServer.java

示例8: getProxy

import java.net.InetSocketAddress; //导入依赖的package包/类
/** Construct a client-side proxy object that implements the named protocol,
 * talking to a server at the named address. 
 * @param <T>*/
@Override
@SuppressWarnings("unchecked")
public <T> ProtocolProxy<T> getProxy(Class<T> protocol, long clientVersion,
                       InetSocketAddress addr, UserGroupInformation ticket,
                       Configuration conf, SocketFactory factory,
                       int rpcTimeout, RetryPolicy connectionRetryPolicy,
                       AtomicBoolean fallbackToSimpleAuth)
  throws IOException {    

  if (connectionRetryPolicy != null) {
    throw new UnsupportedOperationException(
        "Not supported: connectionRetryPolicy=" + connectionRetryPolicy);
  }

  T proxy = (T) Proxy.newProxyInstance(protocol.getClassLoader(),
      new Class[] { protocol }, new Invoker(protocol, addr, ticket, conf,
          factory, rpcTimeout, fallbackToSimpleAuth));
  return new ProtocolProxy<T>(protocol, proxy, true);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:WritableRpcEngine.java

示例9: connectSocket

import java.net.InetSocketAddress; //导入依赖的package包/类
public Socket connectSocket(
        final int connectTimeout,
        final Socket socket,
        final HttpHost host,
        final InetSocketAddress remoteAddress,
        final InetSocketAddress localAddress,
        final HttpContext context) throws IOException {
    final Socket sock = socket != null ? socket : createSocket(context);
    if (localAddress != null) {
        sock.bind(localAddress);
    }
    try {
        sock.connect(remoteAddress, connectTimeout);
    } catch (final IOException ex) {
        try {
            sock.close();
        } catch (final IOException ignore) {
        }
        throw ex;
    }
    return sock;
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:23,代码来源:PlainConnectionSocketFactory.java

示例10: importContact

import java.net.InetSocketAddress; //导入依赖的package包/类
@Override
public DistributedDatabaseContact
importContact(
	InetSocketAddress				address )

	throws DistributedDatabaseException
{
	throwIfNotAvailable();

	DHTPluginContact	contact = getDHT().importContact( address );

	if ( contact == null ){

		throw( new DistributedDatabaseException( "import of '" + address + "' failed" ));
	}

	return( new DDBaseContactImpl( this, contact));
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:19,代码来源:DDBaseImpl.java

示例11: testClientReconnect

import java.net.InetSocketAddress; //导入依赖的package包/类
@Test
public void testClientReconnect() throws IOException, InterruptedException {
    HostProvider hostProvider = mock(HostProvider.class);
    when(hostProvider.size()).thenReturn(1);
    InetSocketAddress inaddr = new InetSocketAddress(1111);
    when(hostProvider.next(anyLong())).thenReturn(inaddr);
    ZooKeeper zk = mock(ZooKeeper.class);
    sc =  SocketChannel.open();

    ClientCnxnSocketNIO nioCnxn = new MockCnxn();
    ClientWatchManager watcher = mock(ClientWatchManager.class);
    ClientCnxn clientCnxn = new ClientCnxn(
            "tmp", hostProvider, 5000,
            zk, watcher, nioCnxn, false);
    clientCnxn.start();
    countDownLatch.await(5000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(countDownLatch.getCount() == 0);
    clientCnxn.close();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:20,代码来源:ClientReconnectTest.java

示例12: getAddress

import java.net.InetSocketAddress; //导入依赖的package包/类
public InetSocketAddress getAddress(HttpClientImpl client) {
    URI uri = uri();
    if (uri == null) {
        return authority();
    }
    int port = uri.getPort();
    if (port == -1) {
        if (uri.getScheme().equalsIgnoreCase("https")) {
            port = 443;
        } else {
            port = 80;
        }
    }
    String host = uri.getHost();
    if (proxy(client) == null) {
        return new InetSocketAddress(host, port);
    } else {
        return InetSocketAddress.createUnresolved(host, port);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:HttpRequestImpl.java

示例13: ZooMap

import java.net.InetSocketAddress; //导入依赖的package包/类
private ZooMap(Builder builder) {
    this.connectionString = builder.connectionString;
    ConnectStringParser connectStringParser = new ConnectStringParser(connectionString);
    if(connectStringParser.getChrootPath() != null) {
        final String connectionStringForChrootCreation = connectStringParser.getServerAddresses().stream().map(InetSocketAddress::toString).collect(Collectors.joining(","));
        try(final CuratorFramework clientForChrootCreation = newCuratorFrameworkClient(builder, connectionStringForChrootCreation)) {
            startAndBlock(clientForChrootCreation);
            tryIt(() -> clientForChrootCreation.createContainers(connectStringParser.getChrootPath()));
        }
    }
    client = newCuratorFrameworkClient(builder, connectionString);
    this.root = builder.root;
    startAndBlock(client);
    if(!root.isEmpty()) {
        tryIt(() -> client.createContainers(root));
    }
}
 
开发者ID:mcmoe,项目名称:zoomap,代码行数:18,代码来源:ZooMap.java

示例14: finishAccept

import java.net.InetSocketAddress; //导入依赖的package包/类
void finishAccept() throws IOException {
    /**
     * Set local/remote addresses. This is currently very inefficient
     * in that it requires 2 calls to getsockname and 2 calls to getpeername.
     * (should change this to use GetAcceptExSockaddrs)
     */
    updateAcceptContext(handle, channel.handle());

    InetSocketAddress local = Net.localAddress(channel.fd);
    final InetSocketAddress remote = Net.remoteAddress(channel.fd);
    channel.setConnected(local, remote);

    // permission check (in context of initiating thread)
    if (acc != null) {
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            public Void run() {
                SecurityManager sm = System.getSecurityManager();
                sm.checkAccept(remote.getAddress().getHostAddress(),
                               remote.getPort());
                return null;
            }
        }, acc);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:WindowsAsynchronousServerSocketChannelImpl.java

示例15: create

import java.net.InetSocketAddress; //导入依赖的package包/类
@Test
public void create() {
    ECKey key = new ECKey();
    String check = UUID.randomUUID().toString();
    PingPeerMessage pingPeerMessage = PingPeerMessage.create("localhost", 80, check, key);
    PongPeerMessage pongPeerMessage = PongPeerMessage.create("localhost", 80, check, key);
    InetSocketAddress address = new InetSocketAddress("localhost", 8080);

    PeerDiscoveryRequest request = PeerDiscoveryRequestBuilder.builder().messageId(check)
            .message(pingPeerMessage).address(address).expectedResponse(DiscoveryMessageType.PONG)
            .expirationPeriod(1000).attemptNumber(1).build();

    Assert.assertNotNull(request);
    Assert.assertTrue(request.validateMessageResponse(pongPeerMessage));
    Assert.assertFalse(request.validateMessageResponse(pingPeerMessage));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:PeerDiscoveryRequestTest.java


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