本文整理汇总了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]);
}
}