本文整理匯總了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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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]);
}
}