android.net.LocalServerSocket Java Examples

The following examples show how to use android.net.LocalServerSocket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TrafficMonitorThread.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        return false;
    }
}
 
Example #2
Source File: ShadowsocksVpnThread.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        app.track(e);
        return false;
    }
}
 
Example #3
Source File: TrafficMonitorThread.java    From Maying with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        return false;
    }
}
 
Example #4
Source File: ShadowsocksVpnThread.java    From Maying with Apache License 2.0 6 votes vote down vote up
/**
 * init server socket
 *
 * @return init failed return false.
 */
private boolean initServerSocket() {
    // if not running, do not init
    if (!isRunning) {
        return false;
    }

    try {
        LocalSocket localSocket = new LocalSocket();
        localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM));
        serverSocket = new LocalServerSocket(localSocket.getFileDescriptor());
        return true;
    } catch (IOException e) {
        VayLog.e(TAG, "unable to bind", e);
        ShadowsocksApplication.app.track(e);
        return false;
    }
}
 
Example #5
Source File: Server.java    From android-advanced-decode with MIT License 6 votes vote down vote up
private Server(String packageName, Application application) {
	this.mApplication = application;
	try {
		this.mServerSocket = new LocalServerSocket(packageName);
		if (Log.isLoggable("InstantRun", 2)) {
			Log.v("InstantRun",
					"Starting server socket listening for package "
							+ packageName + " on "
							+ this.mServerSocket.getLocalSocketAddress());
		}
	} catch (IOException e) {
		Log.e("InstantRun", "IO Error creating local socket at "
				+ packageName, e);
		return;
	}
	startServer();
	if (Log.isLoggable("InstantRun", 2)) {
		Log.v("InstantRun", "Started server for package " + packageName);
	}
}
 
Example #6
Source File: LocalSocketServer.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Nonnull
private static LocalServerSocket bindToSocket(String address) throws IOException {
  int retries = MAX_BIND_RETRIES;
  IOException firstException = null;
  do {
    try {
      LogUtil.e("Trying to bind to @" + address);
      return new LocalServerSocket(address);
    } catch (BindException be) {
      LogUtil.e(be, "Binding error, sleep " + TIME_BETWEEN_BIND_RETRIES_MS + " ms...");
      if (firstException == null) {
        firstException = be;
      }
      Util.sleepUninterruptibly(TIME_BETWEEN_BIND_RETRIES_MS);
    }
  } while (retries-- > 0);

  throw firstException;
}
 
Example #7
Source File: LocalSocketServer.java    From weex with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static LocalServerSocket bindToSocket(String address) throws IOException {
  int retries = MAX_BIND_RETRIES;
  IOException firstException = null;
  do {
    try {
      if (LogUtil.isLoggable(Log.DEBUG)) {
        LogUtil.d("Trying to bind to @" + address);
      }
      return new LocalServerSocket(address);
    } catch (BindException be) {
      LogUtil.w(be, "Binding error, sleep " + TIME_BETWEEN_BIND_RETRIES_MS + " ms...");
      if (firstException == null) {
        firstException = be;
      }
      Util.sleepUninterruptibly(TIME_BETWEEN_BIND_RETRIES_MS);
    }
  } while (retries-- > 0);

  throw firstException;
}
 
Example #8
Source File: CameraConnector.java    From faceswap with Apache License 2.0 6 votes vote down vote up
public void init() {
      try {
          localLoop = new LocalServerSocket("videoserver");
          localReceiver = new LocalSocket();
          localReceiver.connect(localLoop.getLocalSocketAddress());
          localReceiver.setReceiveBufferSize(LOCAL_BUFF_SIZE);
          localReceiver.setSendBufferSize(LOCAL_BUFF_SIZE);
	
	localSender = localLoop.accept();
          localSender.setReceiveBufferSize(LOCAL_BUFF_SIZE);
          localSender.setSendBufferSize(LOCAL_BUFF_SIZE);
	
          Log.d(LOG_TAG, "Done: init()");
}catch(IOException e) {
    Log.e(LOG_TAG, "Error in initializing local socket: " + e);
}
  }
 
Example #9
Source File: LocalSocketServer.java    From stetho with MIT License 6 votes vote down vote up
@Nonnull
private static LocalServerSocket bindToSocket(String address) throws IOException {
  int retries = MAX_BIND_RETRIES;
  IOException firstException = null;
  do {
    try {
      if (LogUtil.isLoggable(Log.DEBUG)) {
        LogUtil.d("Trying to bind to @" + address);
      }
      return new LocalServerSocket(address);
    } catch (BindException be) {
      LogUtil.w(be, "Binding error, sleep " + TIME_BETWEEN_BIND_RETRIES_MS + " ms...");
      if (firstException == null) {
        firstException = be;
      }
      Util.sleepUninterruptibly(TIME_BETWEEN_BIND_RETRIES_MS);
    }
  } while (retries-- > 0);

  throw firstException;
}
 
Example #10
Source File: MediaStream.java    From spydroid-ipcamera with GNU General Public License v3.0 6 votes vote down vote up
protected void createSockets() throws IOException {

		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);
	}
 
Example #11
Source File: Server.java    From android-advanced-decode with MIT License 5 votes vote down vote up
public void run() {
	try {
		for (;;) {
			LocalServerSocket serverSocket = Server.this.mServerSocket;
			if (serverSocket == null) {
				break;
			}
			LocalSocket socket = serverSocket.accept();
			if (Log.isLoggable("InstantRun", 2)) {
				Log.v("InstantRun",
						"Received connection from IDE: spawning connection thread");
			}
			Server.SocketServerReplyThread socketServerReplyThread = new Server.SocketServerReplyThread(
					socket);

			socketServerReplyThread.run();
			if (Server.sWrongTokenCount > 50) {
				if (Log.isLoggable("InstantRun", 2)) {
					Log.v("InstantRun",
							"Stopping server: too many wrong token connections");
				}
				Server.this.mServerSocket.close();
				break;
			}
		}
	} catch (Throwable e) {
		if (Log.isLoggable("InstantRun", 2)) {
			Log.v("InstantRun",
					"Fatal error accepting connection on local socket",
					e);
		}
	}
}
 
Example #12
Source File: MediaStream.java    From libstreaming with Apache License 2.0 5 votes vote down vote up
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]);
		}
	}
 
Example #13
Source File: OpsXServer.java    From AppOpsX with MIT License 4 votes vote down vote up
public LocalServerImpl(String name) throws IOException {
  this.serverSocket = new LocalServerSocket(name);
}