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); }
DaemonMonitorImpl(Context context, File configFile, Notification notification2, Preferences2 preferences2, CmdLineBuilder cmdLineBuilder, IfConfigFactory ifConfigFactory) { mContext = context; mConfigFile = configFile; mNotification2 = notification2; mPreferences2 = preferences2; mCmdLineBuilder = cmdLineBuilder; mIfConfigFactory = ifConfigFactory; mLog = new LogFile( mPreferences2.logFileFor() ); mTagDaemonMonitor = String.format("OpenVPN-DaemonMonitor[%s]", mConfigFile); mgmtSocket = new LocalSocketAddress( new File( mContext.getDir( "mgmt", Context.MODE_PRIVATE ), "mgmt.socket" ).getAbsolutePath(), LocalSocketAddress.Namespace.FILESYSTEM ); reattach(); }
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); }
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); }
@Test(timeout = 1000) public void simplestGet() throws IOException, InterruptedException { // given Service service = startService(); // when LocalSocket clientSocket = new LocalSocket(); clientSocket.connect(new LocalSocketAddress("doesn't matter now")); OutputStream os = clientSocket.getOutputStream(); os.write(GET_1.getBytes()); os.close(); // then InputStream is = clientSocket.getInputStream(); String response = IOUtils.toString(is); System.out.println("response: " + response); String expectedBody = new Test1().test(); assertThat(response, containsString(expectedBody)); }
@Test(timeout = 1000) public void simplestPost() throws IOException, InterruptedException { // given Service service = startService(); // when LocalSocket clientSocket = new LocalSocket(); clientSocket.connect(new LocalSocketAddress("doesn't matter now")); OutputStream os = clientSocket.getOutputStream(); os.write(POST_1.getBytes()); os.close(); // then InputStream is = clientSocket.getInputStream(); String response = IOUtils.toString(is); System.out.println("response: " + response); String expectedBody = new TestPost().post(11, "somename"); assertThat(response, containsString(expectedBody)); }
@Test(timeout = 1000) public void shouldParseLongGetRequests() throws IOException { // given Service service = startService(); // when LocalSocket clientSocket = new LocalSocket(); clientSocket.connect(new LocalSocketAddress("doesn't matter now")); OutputStream os = clientSocket.getOutputStream(); os.write(GET_LONG_1.getBytes()); // two long requests os.write(GET_LONG_1.getBytes()); os.close(); // then InputStream is = clientSocket.getInputStream(); String response = IOUtils.toString(is); System.out.println("response: " + response); String expectedBody = new Test1().test(); assertThat(response, containsString(expectedBody)); }
@Test(timeout = 1000) public void headersShouldBeDecoded() throws IOException { // given Service service = new Service(); service.onCreate(); service.onStartCommand(new Intent(), 0, 0); // when LocalSocket clientSocket = new LocalSocket(); clientSocket.connect(new LocalSocketAddress("doesn't matter now")); OutputStream os = clientSocket.getOutputStream(); os.write(GET_1.getBytes()); os.close(); // then InputStream is = clientSocket.getInputStream(); String response = IOUtils.toString(is); System.out.println("response: " + response); assertThat(response, containsString("localhost")); assertThat(response, containsString("b=2")); assertThat(response, containsString("a=1")); }
@Test(timeout = 1000) public void cookieShouldBeReturned() throws IOException, InterruptedException { // given Service service = new Service(); service.onCreate(); service.onStartCommand(new Intent(), 0, 0); // when LocalSocket clientSocket = new LocalSocket(); clientSocket.connect(new LocalSocketAddress("doesn't matter now")); OutputStream os = clientSocket.getOutputStream(); os.write(GET_1.getBytes()); os.close(); // then InputStream is = clientSocket.getInputStream(); String response = IOUtils.toString(is); System.out.println("response: " + response); String expectedBody = "Set-Cookie: COOKIE_NAME=cookieValuecookieValue"; assertThat(response, containsString(expectedBody)); }
@Test(timeout = 1000) public void cookieShouldBeAccepted() throws IOException, InterruptedException { // given Service service = new Service(); service.onCreate(); service.onStartCommand(new Intent(), 0, 0); // when LocalSocket clientSocket = new LocalSocket(); clientSocket.connect(new LocalSocketAddress("doesn't matter now")); OutputStream os = clientSocket.getOutputStream(); os.write(GET_2.getBytes()); os.close(); // then InputStream is = clientSocket.getInputStream(); String response = IOUtils.toString(is); System.out.println("response: " + response); String expectedBody = "cookieValuecookieValue"; assertThat(response, containsString(expectedBody)); }
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); } }
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]); } }
@SuppressLint("UseSparseArrays") public LocalSocketThread(String socketPath) { mSocketPath = new LocalSocketAddress(socketPath); mInputStream = null; mOutputStream = null; mMessages = new HashMap<>(); }
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]); } }
/** * Creates a socket to write the AR Animation data. * * @param socketAddress LocalSocket address. */ private void connectLocalServer(final String socketAddress) { closeLocalServer(); try { mLocalRenderAnimationSocket = new LocalSocket(); mLocalRenderAnimationSocket.connect(new LocalSocketAddress(socketAddress)); } catch (Exception e) { if (Dbg.DEBUG) { Dbg.e("Failed connecting socket for AR Animation data."); } } }
/** * Creates a socket to write the AR Animation data. * @param socketAddress LocalSocket address. */ private void connectLocalServer(final String socketAddress) { closeLocalServer(); try { mLocalRenderAnimationSocket = new LocalSocket(); mLocalRenderAnimationSocket.connect(new LocalSocketAddress(socketAddress)); } catch (Exception e) { if (Dbg.DEBUG) { Dbg.e("Failed connecting socket for AR Animation data."); } } }
public boolean connect() { mSocket = new LocalSocket(); try { mSocket.connect(new LocalSocketAddress("fota", LocalSocketAddress.Namespace.RESERVED)); mIn = mSocket.getInputStream(); mOut = mSocket.getOutputStream(); return true; } catch (IOException e) { e.printStackTrace(); } return false; }
ManagementThread(DaemonMonitorImpl daemonMonitor, Notification notification2, Preferences2 preferences2, LocalSocketAddress mgmtSocket, IfConfigFactory ifConfigFactory) { mDaemonMonitor = daemonMonitor; mNotification2 = notification2; mPreferences2 = preferences2; mTAG_MT = daemonMonitor.mTagDaemonMonitor + "-mgmt"; mMgmtSocket = mgmtSocket; mIfConfigFactory = ifConfigFactory; ifConfig = mIfConfigFactory.createIfConfig(); }
protected void createSockets() throws IOException { if (sPipeApi == PIPE_API_LS) { final String LOCAL_ADDR = "com.jjcamera.apps.iosched.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]); } }
@SuppressLint("UseSparseArrays") public LocalSocketThread(String socketPath) { mSocketPath = new LocalSocketAddress(socketPath); mInputStream = null; mOutputStream = null; mMessages = new HashMap<Integer, Message>(); }
private boolean initializeLocalSocket(){ receiver = new LocalSocket(); try { lss = new LocalServerSocket("VideoCamera"); receiver.connect(new LocalSocketAddress("VideoCamera")); receiver.setReceiveBufferSize(500000); receiver.setSendBufferSize(500000); sender = lss.accept(); sender.setReceiveBufferSize(500000); sender.setSendBufferSize(500000); } catch (IOException e) { return false; } return true; }
private void initLocalSocket() { LocalSocket receiver = new LocalSocket(); try { LocalServerSocket lss = new LocalServerSocket("H264"); receiver.connect(new LocalSocketAddress("H264")); receiver.setReceiveBufferSize(500000); receiver.setSendBufferSize(500000); sender = lss.accept(); sender.setReceiveBufferSize(500000); sender.setSendBufferSize(500000); } catch (IOException e1) { e1.printStackTrace(); } }
protected void createLocalSockets() throws IOException { Log.d(LOG_TAG, "Binding to " + localName()); serverSocket = new LocalServerSocket(localName()); receiverSocket = new LocalSocket(); receiverSocket.connect(new LocalSocketAddress(localName())); receiverSocket.setReceiveBufferSize(BUFFER_SIZE); receiverSocket.setSoTimeout(SO_TIMEOUT); senderSocket = serverSocket.accept(); senderSocket.setSendBufferSize(BUFFER_SIZE); }
public void writeSocket(String message) throws IOException { Log.i(TAG, "writeSocket, " + message); LocalSocket sender = new LocalSocket(); sender.connect(new LocalSocketAddress(SOCKET_ADDRESS)); sender.getOutputStream().write(message.getBytes()); sender.getOutputStream().close(); sender.close(); }
private void createSockets() throws IOException { mReceiver = new LocalSocket(); mReceiver.connect( new LocalSocketAddress("net.majorkernelpanic.librtp-" + mSocketId ) ); mReceiver.setReceiveBufferSize(500000); mSender = mLss.accept(); mSender.setSendBufferSize(500000); }
@Override public void onResume() { if (!Sipdroid.release) Log.i("SipUA:","on resume"); justplay = intent.hasExtra("justplay"); if (!justplay) { receiver = new LocalSocket(); try { lss = new LocalServerSocket("Sipdroid"); receiver.connect(new LocalSocketAddress("Sipdroid")); receiver.setReceiveBufferSize(500000); receiver.setSendBufferSize(500000); sender = lss.accept(); sender.setReceiveBufferSize(500000); sender.setSendBufferSize(500000); } catch (IOException e1) { if (!Sipdroid.release) e1.printStackTrace(); super.onResume(); finish(); return; } checkForCamera(); mVideoPreview.setVisibility(View.VISIBLE); if (!mMediaRecorderRecording) initializeVideo(); startVideoRecording(); } else if (Receiver.engine(mContext).getRemoteVideo() != 0 && PreferenceManager.getDefaultSharedPreferences(this).getString(org.sipdroid.sipua.ui.Settings.PREF_SERVER, org.sipdroid.sipua.ui.Settings.DEFAULT_SERVER).equals(org.sipdroid.sipua.ui.Settings.DEFAULT_SERVER)) { mVideoFrame.setVideoURI(Uri.parse("rtsp://"+Receiver.engine(mContext).getRemoteAddr()+"/"+ Receiver.engine(mContext).getRemoteVideo()+"/sipdroid")); mVideoFrame.setMediaController(mMediaController = new MediaController(this)); mVideoFrame.setOnErrorListener(this); mVideoFrame.requestFocus(); mVideoFrame.start(); } mRecordingTimeView.setText(""); mRecordingTimeView.setVisibility(View.VISIBLE); mHandler.removeMessages(UPDATE_RECORD_TIME); mHandler.sendEmptyMessage(UPDATE_RECORD_TIME); super.onResume(); }
public RtklibLocalSocketThread(String socketPath) { mSocketPath = new LocalSocketAddress(socketPath, Namespace.FILESYSTEM); mInputStream = DummyInputStream.instance; mOutputStream = DummyOutputStream.instance; mReconnectTimeout = RECONNECT_TIMEOUT_MS; mBindpoint = ""; }
private boolean connectLoop() { LocalSocket s = new LocalSocket(); if (!TextUtils.isEmpty(mBindpoint)) { try { s.bind(new LocalSocketAddress(mBindpoint)); } catch (IOException e1) { e1.printStackTrace(); } } while(!cancelRequested) { try { s.connect(mSocketPath); synchronized(this) { mSocket = s; mInputStream = s.getInputStream(); mOutputStream = s.getOutputStream(); } return true; }catch (IOException e) { synchronized(this) { if (cancelRequested) { return false; } if (!isDeviceReady()) { return true; } setState(STATE_RECONNECTING); try { wait(mReconnectTimeout); } catch(InterruptedException ie) { return false; } } } } return false; }
public LocalSocketThread(String socketPath) { mSocketPath = new LocalSocketAddress(socketPath); mInputStream = null; mOutputStream = null; mMessages = new HashMap<>(); }
private void startLocalClient(String name, String message) throws Exception { // Construct a local socket LocalSocket clientSocket = new LocalSocket(); try { // Set the socket namespace LocalSocketAddress.Namespace namespace; if (isFilesystemSocket(name)) { namespace = LocalSocketAddress.Namespace.FILESYSTEM; } else { namespace = LocalSocketAddress.Namespace.ABSTRACT; } // Construct local socket address LocalSocketAddress address = new LocalSocketAddress(name, namespace); // Connect to local socket Log.i(TAG, "Connecting to " + name); clientSocket.connect(address); Log.i(TAG, "Connected."); // Get message as bytes byte[] messageBytes = message.getBytes(); // Send message bytes to the socket Log.i(TAG, "Sending to the socket..."); OutputStream outputStream = clientSocket.getOutputStream(); outputStream.write(messageBytes); Log.i(TAG, String.format("Sent %d bytes: %s",messageBytes.length, message)); // Receive the message back from the socket Log.i(TAG, "Receiving from the socket..."); InputStream inputStream = clientSocket.getInputStream(); int readSize = inputStream.read(messageBytes); String receivedMessage = new String(messageBytes, 0, readSize); Log.i(TAG, String.format("Received %d bytes: %s", readSize, receivedMessage)); // Close streams outputStream.close(); inputStream.close(); } finally { // Close the local socket clientSocket.close(); } }