Socket getLocalSocketAddress - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Socket getLocalSocketAddress method.

This code example shows how to use the following methods:getLocalSocketAddress
    return socket.getRemoteSocketAddress().toString();
  } 
 
  @Override 
  public String getLocalAddressString() {
    return socket.getLocalSocketAddress().toString();
  } 
   
  @Override 
  public InputStream getInputStream() throws IOException {
    return in;
  } 
 
  @Override 
  public OutputStream getOutputStream() throws IOException {
    return out;
  } 
 
  @Override 
  public boolean isLocal() { 
6
CodeRank
This code example shows how to use the following methods:getInputStream, getLocalSocketAddress, getOutputStream, getRemoteSocketAddress
     *  
     */ 
    public SocketEndPoint(Socket socket)
    	throws IOException	 
    { 
        super(socket.getInputStream(),socket.getOutputStream());
        _socket=socket;
        _local=(InetSocketAddress)_socket.getLocalSocketAddress();
        _remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
    } 
 
    /* (non-Javadoc) 
     * @see org.mortbay.io.BufferIO#isClosed() 
     */ 
    public boolean isOpen() 
    { 
        return super.isOpen() && _socket!=null && !_socket.isClosed() && !_socket.isInputShutdown() && !_socket.isOutputShutdown();
    } 
 
    /* ------------------------------------------------------------ */ 
7
CodeRank
This code example shows how to use the following methods:getInputStream, getLocalSocketAddress, getOutputStream
    @Test
    public void requestPathWithNoReceiver() throws Exception
    { 
        HttpRequestDispatcherWork httpRequestDispatcherWork = new HttpRequestDispatcherWork(mockHttpConnector, mockSocket);
        setUpSocketMessage(); 
        when(mockSocket.getLocalSocketAddress()).thenReturn(new InetSocketAddress(0));
        when(mockHttpConnector.lookupReceiver(any(Socket.class), any(RequestLine.class))).thenThrow(mockNoReceiverForEndpointException);
        ByteArrayOutputStream socketOutput = new ByteArrayOutputStream();
        when(mockSocket.getOutputStream()).thenReturn(socketOutput);
        httpRequestDispatcherWork.run();
        String response = new String(socketOutput.toByteArray());
        assertThat(response.startsWith("HTTP/1.0 404 Not Found"), Is.is(true));
    } 
 
    @Test
    public void onValidUriProcessRequest() throws Exception
    { 
        HttpRequestDispatcherWork httpRequestDispatcherWork = new HttpRequestDispatcherWork(mockHttpConnector, mockSocket);
        when(mockHttpConnector.lookupReceiver(isA(Socket.class), isA(RequestLine.class))).thenReturn(mockHttpMessageReceiver);
        setUpSocketMessage(); 

6
CodeRank
This code example shows how to use the following methods:getInputStream, getLocalSocketAddress, getOutputStream, getRemoteSocketAddress, getSoTimeout
                    e.printStackTrace();
                } 
            } 
        }.start();
         
        Socket s0 = new Socket(server.getInetAddress(),server.getLocalPort());
        Socket s1 = accepted.exchange(null,5,TimeUnit.SECONDS);
         
        SocketEndPoint in = new SocketEndPoint(s0);
        SocketEndPoint out = new SocketEndPoint(s1);
         
        check(in,out);
    } 
     
     
    private void check(EndPoint in, EndPoint out) throws Exception
    { 
        String data="Now is the time for all good men to come to the aid of the party";
        Buffer send = new ByteArrayBuffer(data);
        Buffer receive = new IndirectNIOBuffer(4096);

7
CodeRank
This code example shows how to use the following methods:getInputStream, getLocalSocketAddress, getOutputStream, getRemoteSocketAddress, setSoTimeout
     * 
     */ 
    protected SocketEndPoint(Socket socket, int maxIdleTime)
        throws IOException 
    { 
        super(socket.getInputStream(),socket.getOutputStream());
        _socket=socket;
        _local=(InetSocketAddress)_socket.getLocalSocketAddress();
        _remote=(InetSocketAddress)_socket.getRemoteSocketAddress();
        _socket.setSoTimeout(maxIdleTime>0?maxIdleTime:0);
        super.setMaxIdleTime(maxIdleTime);
    } 
 
    /* ------------------------------------------------------------ */ 
    /* (non-Javadoc) 
     * @see org.eclipse.io.BufferIO#isClosed() 
     */ 
    @Override 
    public boolean isOpen() 
    { 
6
CodeRank
This code example shows how to use the following methods:getInputStream, getLocalSocketAddress, getOutputStream, isConnected
			return false; 
		} 
		 
		 
		// try opening socket even if it's not null. 
		if (socket.isConnected() != true) {
			openSocket(); 
		} 
 
		// Is the socket open? 
		if (socket.isConnected() != true) {
			if (DEBUG) msg("After opening socket, it was not connected.");
			return false; 
		} 
 
		if (DEBUG) msg("Successfully opened socket.");
		return true; 
	} 
 
	/** 

6
CodeRank
This code example shows how to use the following methods:getInetAddress, getLocalPort, getLocalSocketAddress, getReceiveBufferSize
	       } 
	   } 
	    
	   private static void show(Socket socket) throws SocketException {
		   //System.out.println("getChannel : " + socket.getChannel().toString()); 
		   System.out.println("getInetAddress : " + socket.getInetAddress().toString());
		   System.out.println("getLocalSocketAddress : " + socket.getLocalSocketAddress().toString());
		   System.out.println("getLocalPort : " + socket.getLocalPort());
		   System.out.println("getReceiveBufferSize : " + socket.getReceiveBufferSize());
	   } 
} 
6
CodeRank
This code example shows how to use the following methods:close, getLocalSocketAddress, shutdownOutput
                    logger.debug("Closing: " + socket);
                } 
 
                try 
                { 
                    socket.shutdownOutput();
                } 
                catch (UnsupportedOperationException e)
                { 
                    //Can't shutdown in/output on SSL sockets 
                } 
 
                if (in != null)
                { 
                    in.close();
                } 
                if (out != null)
                { 
                    out.close();
                } 

5
CodeRank
This code example shows how to use the following methods:sleep, bind, connect, getLocalSocketAddress, isBound
        client.addConnection(readerWriter2);
         
 
        assertNotNull(clientManager.getTurnClient(session));
         
        final Socket socket = new Socket();
         
        // For it to bind to an ephemeral local port.  Make sure we're able 
        // to connect. 
        socket.bind(null);
         
        assertTrue(socket.isBound());
        client.handleConnect((InetSocketAddress)socket.getLocalSocketAddress());
         
        final InetSocketAddress relayAddress = client.getRelayAddress();
        m_log.debug("Connecting to relay address: {}", relayAddress);
         
         
        // Make sure we can connect to the allocated address for the TURN 
        // client. 

6
CodeRank
This code example shows how to use the following methods:getLocalSocketAddress, getRemoteSocketAddress
 
    @Override 
    public String toString() {
        if (this.socket != null) {
            final StringBuilder buffer = new StringBuilder();
            final SocketAddress remoteAddress = this.socket.getRemoteSocketAddress();
            final SocketAddress localAddress = this.socket.getLocalSocketAddress();
            if (remoteAddress != null && localAddress != null) {
                formatAddress(buffer, localAddress);
                buffer.append("<->");
                formatAddress(buffer, remoteAddress);
            } 
            return buffer.toString();
        } else { 
            return super.toString(); 
        } 
    } 
 
} 
5
CodeRank
getLocalSocketAddress Method Overview
Returns the address of the endpoint this socket is bound to.
See Code Examples for other Java 8 Socket Methods: