Search in sources :

Example 76 with Socket

use of java.net.Socket in project hazelcast by hazelcast.

the class InitConnectionTask method bindSocket.

private void bindSocket(SocketChannel socketChannel) throws IOException {
    InetAddress inetAddress = getInetAddress();
    Socket socket = socketChannel.socket();
    if (connectionManager.useAnyOutboundPort()) {
        SocketAddress socketAddress = new InetSocketAddress(inetAddress, 0);
        socket.bind(socketAddress);
    } else {
        IOException ex = null;
        int retryCount = connectionManager.getOutboundPortCount() * 2;
        for (int i = 0; i < retryCount; i++) {
            int port = connectionManager.acquireOutboundPort();
            SocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
            try {
                socket.bind(socketAddress);
                return;
            } catch (IOException e) {
                ex = e;
                logger.finest("Could not bind port[ " + port + "]: " + e.getMessage());
            }
        }
        throw ex;
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Example 77 with Socket

use of java.net.Socket in project gitblit by gitblit.

the class LaunchWithUITestConfig method shutdownGitBlitServer.

private static void shutdownGitBlitServer(int shutdownPort) {
    try {
        Socket s = new Socket(InetAddress.getByName("127.0.0.1"), shutdownPort);
        OutputStream out = s.getOutputStream();
        System.out.println("Sending Shutdown Request to " + Constants.NAME);
        out.write("\r\n".getBytes());
        out.flush();
        s.close();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Socket(java.net.Socket)

Example 78 with Socket

use of java.net.Socket in project libstreaming by fyhertz.

the class RtspClient method tryConnection.

private void tryConnection() throws IOException {
    mCSeq = 0;
    mSocket = new Socket(mParameters.host, mParameters.port);
    mBufferedReader = new BufferedReader(new InputStreamReader(mSocket.getInputStream()));
    mOutputStream = new BufferedOutputStream(mSocket.getOutputStream());
    sendRequestAnnounce();
    sendRequestSetup();
    sendRequestRecord();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket) RtpSocket(net.majorkernelpanic.streaming.rtp.RtpSocket)

Example 79 with Socket

use of java.net.Socket in project fqrouter by fqrouter.

the class DNSConnection method getInetAddress.

/**
 * NOTE: Result != null unless connection is closed.
 **
 * @since 2.0
 */
public final InetAddress getInetAddress() {
    Socket socket;
    InetAddress address = null;
    if ((socket = this.socket) != null)
        address = socket.getInetAddress();
    return address;
}
Also used : InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 80 with Socket

use of java.net.Socket in project fqrouter by fqrouter.

the class DNSConnection method openIncoming.

/**
 * NOTE: old connection should be closed. Wait for any incoming
 * connection and accept it. If listening is not active or if
 * SecurityException is caught then SocketException is thrown. If
 * waiting fails then InterruptedIOException is thrown. Must be
 * synchronized outside.
 **
 * @since 3.0
 */
public void openIncoming() throws IOException {
    ServerSocket curListener;
    if ((curListener = listener) != null) {
        try {
            Socket socket = curListener.accept();
            BufferedInputStream in = new BufferedInputStream(socket.getInputStream(), DNSMsgHeader.UDP_PACKET_LEN);
            this.out = socket.getOutputStream();
            this.in = in;
            this.msgBytes = null;
            this.socket = socket;
            return;
        } catch (SecurityException e) {
        }
    }
    throw new SocketException(curListener == null ? "Not listening" : "SecurityException: accept()");
}
Also used : SocketException(java.net.SocketException) BufferedInputStream(java.io.BufferedInputStream) ServerSocket(java.net.ServerSocket) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Aggregations

Socket (java.net.Socket)1633 IOException (java.io.IOException)705 ServerSocket (java.net.ServerSocket)578 OutputStream (java.io.OutputStream)377 InetSocketAddress (java.net.InetSocketAddress)367 Test (org.junit.Test)362 InputStream (java.io.InputStream)259 InputStreamReader (java.io.InputStreamReader)179 BufferedReader (java.io.BufferedReader)160 SocketException (java.net.SocketException)137 SSLSocket (javax.net.ssl.SSLSocket)111 SocketTimeoutException (java.net.SocketTimeoutException)97 UnknownHostException (java.net.UnknownHostException)86 ConnectException (java.net.ConnectException)84 InetAddress (java.net.InetAddress)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 OutputStreamWriter (java.io.OutputStreamWriter)70 DataOutputStream (java.io.DataOutputStream)68 ServletOutputStream (javax.servlet.ServletOutputStream)68 CountDownLatch (java.util.concurrent.CountDownLatch)65