當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalServerSocket類代碼示例

本文整理匯總了Java中android.net.LocalServerSocket的典型用法代碼示例。如果您正苦於以下問題:Java LocalServerSocket類的具體用法?Java LocalServerSocket怎麽用?Java LocalServerSocket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocalServerSocket類屬於android.net包,在下文中一共展示了LocalServerSocket類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSockets

import android.net.LocalServerSocket; //導入依賴的package包/類
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);
	}
 
開發者ID:ghazi94,項目名稱:Android_CCTV,代碼行數:20,代碼來源:MediaStream.java

示例2: Server

import android.net.LocalServerSocket; //導入依賴的package包/類
private Server(String packageName) {
    try {
        serverSocket = new LocalServerSocket(packageName);
        if (Log.isLoggable(Logging.LOG_TAG, Log.VERBOSE)) {
            Log.v(Logging.LOG_TAG, "Starting server socket listening for package " + packageName
                    + " on " + serverSocket.getLocalSocketAddress());
        }
    } catch (IOException e) {
        Log.e(Logging.LOG_TAG, "IO Error creating local socket at " + packageName, e);
        return;
    }
    startServer();

    if (Log.isLoggable(Logging.LOG_TAG, Log.VERBOSE)) {
        Log.v(Logging.LOG_TAG, "Started server for package " + packageName);
    }
}
 
開發者ID:typ0520,項目名稱:fastdex,代碼行數:18,代碼來源:Server.java

示例3: bindToSocket

import android.net.LocalServerSocket; //導入依賴的package包/類
@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;
}
 
開發者ID:misakuo,項目名稱:Dream-Catcher,代碼行數:20,代碼來源:LocalSocketServer.java

示例4: bindToSocket

import android.net.LocalServerSocket; //導入依賴的package包/類
@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;
}
 
開發者ID:Laisly,項目名稱:weex,代碼行數:22,代碼來源:LocalSocketServer.java

示例5: init

import android.net.LocalServerSocket; //導入依賴的package包/類
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);
}
  }
 
開發者ID:cmusatyalab,項目名稱:faceswap,代碼行數:18,代碼來源:CameraConnector.java

示例6: Server

import android.net.LocalServerSocket; //導入依賴的package包/類
/**
 * 私有構造方法
 * 主要是實例化一個 LocalServerSocket
 * 然後調用 startServer() 方法
 *
 * @param packageName packageName
 * @param application application
 */
private Server(@NonNull String packageName, @NonNull Application application) {
    mApplication = application;
    try {
        mServerSocket = new LocalServerSocket(packageName);
        if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
            Log.v(LOG_TAG, "Starting server socket listening for package " + packageName
                + " on " + mServerSocket.getLocalSocketAddress());
        }
    } catch (IOException e) {
        Log.e(LOG_TAG, "IO Error creating local socket at " + packageName, e);
        return;
    }
    startServer();

    if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) {
        Log.v(LOG_TAG, "Started server for package " + packageName);
    }
}
 
開發者ID:CaMnter,項目名稱:AndroidLife,代碼行數:27,代碼來源:Server.java

示例7: create

import android.net.LocalServerSocket; //導入依賴的package包/類
@VisibleForTesting
static FileDescriptorFactory create(String address, String... cmd) throws IOException {
    // must be created before the process
    final LocalServerSocket socket = new LocalServerSocket(address);
    try {
        final Process shell = new ProcessBuilder(cmd)
                .redirectErrorStream(true)
                .start();

        final FileDescriptorFactory result = new FileDescriptorFactory(shell, socket);

        result.startServer();

        return result;
    } catch (Throwable t) {
        shut(socket);

        throw t;
    }
}
 
開發者ID:chdir,項目名稱:fdshare,代碼行數:21,代碼來源:FileDescriptorFactory.java

示例8: Server

import android.net.LocalServerSocket; //導入依賴的package包/類
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);
    }
}
 
開發者ID:xu6148152,項目名稱:binea_project_for_android,代碼行數:18,代碼來源:Server.java

示例9: createSockets

import android.net.LocalServerSocket; //導入依賴的package包/類
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(1000000);
		mReceiver.setSoTimeout(3000);
		mSender = mLss.accept();
		mSender.setSendBufferSize(1000000);
	}
 
開發者ID:Oo-Dev,項目名稱:OoDroid2,代碼行數:20,代碼來源:MediaStream.java

示例10: createSockets

import android.net.LocalServerSocket; //導入依賴的package包/類
protected void createSockets() throws IOException {

		final String LOCAL_ADDR = "edu.ucsb.cs.capstone.letmypeoplecode.smartrover.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);
	}
 
開發者ID:sciencectn,項目名稱:SmartRover,代碼行數:20,代碼來源:MediaStream.java

示例11: LocalSocketEventReporter

import android.net.LocalServerSocket; //導入依賴的package包/類
public LocalSocketEventReporter(String socketName, int timeoutInSec) {
    EventServer server1;
    try {
        LocalServerSocket socket = new LocalServerSocket(socketName);
        server1 = new EventServer(socket, timeoutInSec, TimeUnit.SECONDS);
    } catch (IOException e) {
        server1 = null;
        new RuntimeException("Unable to create server socket");
    }
    this.server = server1;
}
 
開發者ID:Microsoft,項目名稱:AppCenter-Test-Espresso-Extensions,代碼行數:12,代碼來源:LocalSocketEventReporter.java

示例12: sendSync_will_return_false_if_no_one_listens

import android.net.LocalServerSocket; //導入依賴的package包/類
@Test
public void sendSync_will_return_false_if_no_one_listens() throws Exception {
    String socketName = "junitevent";
    LocalServerSocket socket = new LocalServerSocket(socketName);
    EventServer server = new EventServer(socket, 10, TimeUnit.MILLISECONDS);

    boolean b = server.sendSync(Event.create("id", EventType.started, "testName", "className", "1"));
    server.stop();

    assertFalse("sendSync without a listener should return false", b);
}
 
開發者ID:Microsoft,項目名稱:AppCenter-Test-Espresso-Extensions,代碼行數:12,代碼來源:EventServerTest.java

示例13: sendSync_will_return_true_if_some_one_listens

import android.net.LocalServerSocket; //導入依賴的package包/類
@Test
public void sendSync_will_return_true_if_some_one_listens() throws Exception {
    String socketName = "junitevent2";
    LocalServerSocket socket = new LocalServerSocket(socketName);
    EventServer server = new EventServer(socket, 10, TimeUnit.SECONDS);
    TestEventClient client = new TestEventClient(socketName);

    boolean b = server.sendSync(Event.create("id", EventType.started, "testName", "className", "1"));
    server.stop();
    client.stop();

    assertTrue("sendSync with a listener should return true", b);
}
 
開發者ID:Microsoft,項目名稱:AppCenter-Test-Espresso-Extensions,代碼行數:14,代碼來源:EventServerTest.java

示例14: LocalProxySocket

import android.net.LocalServerSocket; //導入依賴的package包/類
public LocalProxySocket(Socket original) throws TorException {
    super();
    try {
        // Prepare LocalSocket which will be used to trick the SSLSocket (or any other one)
        localSocketSend = new LocalSocket();
        // Local socket name
        String socketName = "local" + UUID.randomUUID();
        localServerSocket = new LocalServerSocket(socketName);
        localSocketSend.connect(new LocalSocketAddress(socketName));
        localSocketRecv = localServerSocket.accept();
        this.originalSocket = original;
        // Create 2 Threads which are taking care of the communication between the LocalSocket and the original Socket
        LocalProxyWorker lpw1 = new LocalProxyWorker(localSocketRecv.getInputStream(), originalSocket.getOutputStream(), "to");
        LocalProxyWorker lpw2 = new LocalProxyWorker(originalSocket.getInputStream(), localSocketRecv.getOutputStream(), "from");
        Thread t1 = new Thread(lpw1);
        Thread t2 = new Thread(lpw2);
        t1.start();
        t2.start();
        // Prepare this Socket to contain the FileDescriptor of the LocalSocket
        FileDescriptor fd = localSocketSend.getFileDescriptor();
        SocketImpl socketImpl = (SocketImpl) Class.forName("java.net.PlainSocketImpl").getConstructor(FileDescriptor.class).newInstance(fd);
        Field implField = this.getClass().getSuperclass().getDeclaredField("impl");
        implField.setAccessible(true);
        implField.set(this, socketImpl);
    } catch (Exception e) {
        LOG.debug("Got Exception while trying to create LocalProxySocket", e);
        throw new TorException("could not create LocalProxySocket", e);
    }
}
 
開發者ID:B4dT0bi,項目名稱:silvertunnel-ng,代碼行數:30,代碼來源:LocalProxySocket.java

示例15: createSockets

import android.net.LocalServerSocket; //導入依賴的package包/類
protected void createSockets() throws IOException {

		if (sPipeApi == PIPE_API_LS) {
			
			final String LOCAL_ADDR = "com.galuu.ev3videocontrol.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]);
		}
	}
 
開發者ID:galme,項目名稱:ROLF-EV3,代碼行數:29,代碼來源:MediaStream.java


注:本文中的android.net.LocalServerSocket類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。