Search in sources :

Example 51 with LocalSocket

use of android.net.LocalSocket in project stetho by facebook.

the class LocalSocketServer method listenOnAddress.

private void listenOnAddress(String address) throws IOException {
    mServerSocket = bindToSocket(address);
    LogUtil.i("Listening on @" + address);
    while (!Thread.interrupted()) {
        try {
            // Use previously accepted socket the first time around, otherwise wait to
            // accept another.
            LocalSocket socket = mServerSocket.accept();
            // Start worker thread
            Thread t = new WorkerThread(socket, mSocketHandler);
            t.setName(WORKER_THREAD_NAME_PREFIX + "-" + mFriendlyName + "-" + mThreadId.incrementAndGet());
            t.setDaemon(true);
            t.start();
        } catch (SocketException se) {
            // ignore exception if interrupting the thread
            if (Thread.interrupted()) {
                break;
            }
            LogUtil.w(se, "I/O error");
        } catch (InterruptedIOException ex) {
            break;
        } catch (IOException e) {
            LogUtil.w(e, "I/O error initialising connection thread");
            break;
        }
    }
    LogUtil.i("Server shutdown on @" + address);
}
Also used : SocketException(java.net.SocketException) InterruptedIOException(java.io.InterruptedIOException) LocalSocket(android.net.LocalSocket) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 52 with LocalSocket

use of android.net.LocalSocket in project libstreaming by fyhertz.

the class MediaStream method createSockets.

protected void createSockets() throws IOException {
    if (sPipeApi == PIPE_API_LS) {
        final String LOCAL_ADDR = "net.majorkernelpanic.streaming-";
        for (int i = 0; i < 10; i++) {
            try {
                mSocketId = new Random().nextInt();
                mLss = new LocalServerSocket(LOCAL_ADDR + mSocketId);
                break;
            } catch (IOException e1) {
            }
        }
        mReceiver = new LocalSocket();
        mReceiver.connect(new LocalSocketAddress(LOCAL_ADDR + mSocketId));
        mReceiver.setReceiveBufferSize(500000);
        mReceiver.setSoTimeout(3000);
        mSender = mLss.accept();
        mSender.setSendBufferSize(500000);
    } else {
        Log.e(TAG, "parcelFileDescriptors createPipe version = Lollipop");
        mParcelFileDescriptors = ParcelFileDescriptor.createPipe();
        mParcelRead = new ParcelFileDescriptor(mParcelFileDescriptors[0]);
        mParcelWrite = new ParcelFileDescriptor(mParcelFileDescriptors[1]);
    }
}
Also used : Random(java.util.Random) LocalServerSocket(android.net.LocalServerSocket) LocalSocketAddress(android.net.LocalSocketAddress) ParcelFileDescriptor(android.os.ParcelFileDescriptor) LocalSocket(android.net.LocalSocket) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint)

Aggregations

LocalSocket (android.net.LocalSocket)52 IOException (java.io.IOException)44 LocalSocketAddress (android.net.LocalSocketAddress)33 FileDescriptor (java.io.FileDescriptor)26 ParcelFileDescriptor (android.os.ParcelFileDescriptor)17 LocalServerSocket (android.net.LocalServerSocket)14 SmallTest (android.test.suitebuilder.annotation.SmallTest)11 RemoteException (android.os.RemoteException)10 InputStream (java.io.InputStream)8 Credentials (android.net.Credentials)6 Message (android.os.Message)6 SocketException (java.net.SocketException)6 BufferedWriter (java.io.BufferedWriter)2 DataInputStream (java.io.DataInputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 SuppressLint (android.annotation.SuppressLint)1 InterruptedIOException (java.io.InterruptedIOException)1 OutputStream (java.io.OutputStream)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1