Android LocalSocket - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android LocalSocket class.

This code example shows how to use the following methods:close, connect, getInputStream, getOutputStream
        if (mSocket != null) {
            return true; 
        } 
        Slog.i(TAG, "connecting...");
        try { 
            mSocket = new LocalSocket();
 
            LocalSocketAddress address = new LocalSocketAddress("installd",
                    LocalSocketAddress.Namespace.RESERVED);
 
            mSocket.connect(address);
 
            mIn = mSocket.getInputStream();
            mOut = mSocket.getOutputStream();
        } catch (IOException ex) {
            disconnect(); 
            return false; 
        } 
        return true; 
    } 

8
CodeRank
This code example shows how to use the following methods:close, connect, getInputStream, getOutputStream
        if (mSocket != null) {
            return true; 
        } 
        Slog.i(TAG, "connecting...");
        try { 
            mSocket = new LocalSocket();
 
            LocalSocketAddress address = new LocalSocketAddress("installd",
                    LocalSocketAddress.Namespace.RESERVED);
 
            mSocket.connect(address);
 
            mIn = mSocket.getInputStream();
            mOut = mSocket.getOutputStream();
        } catch (IOException ex) {
            disconnect(); 
            return false; 
        } 
        return true; 
    } 

8
CodeRank
This code example shows how to use the following methods:connect, setReceiveBufferSize
        isConnected_ = false;
	} 
 
	public boolean InitLoop(int recvBufferSize, int sendBufferSize)
	{		 
        receiver = new LocalSocket();
		try { 
			receiver.connect(new LocalSocketAddress(localAddress));
			receiver.setReceiveBufferSize(recvBufferSize);
			//receiver.setSendBufferSize(512); 
			sender = lss.accept();
			//sender.setReceiveBufferSize(512); 
			sender.setSendBufferSize(sendBufferSize);
		} catch (IOException e) {
			e.printStackTrace();
			return false; 
		}		 
		isConnected_ = true;
        return true; 
	} 
7
CodeRank
This code example shows how to use the following methods:close, connect, getInputStream, getOutputStream
        if (mSocket != null) {
            return true; 
        } 
        Log.i(TAG, "connecting...");
        try { 
            mSocket = new LocalSocket();
 
            LocalSocketAddress address = new LocalSocketAddress(
                "installd", LocalSocketAddress.Namespace.RESERVED);
 
            mSocket.connect(address);
 
            mIn = mSocket.getInputStream();
            mOut = mSocket.getOutputStream();
        } catch (IOException ex) {
            disconnect(); 
            return false; 
        } 
        return true; 
    } 

7
CodeRank
This code example shows how to use the following methods:connect, setReceiveBufferSize, setSendBufferSize
		receiver = null;
	} 
 
	public boolean InitLoop() 
	{		 
        receiver = new LocalSocket();
		try { 
			receiver.connect(new LocalSocketAddress(localAddress));
			receiver.setReceiveBufferSize(1000);
			receiver.setSendBufferSize(1000);
			sender = lss.accept();
			sender.setReceiveBufferSize(1000);
			sender.setSendBufferSize(1000);
			 
		} catch (IOException e) {
			e.printStackTrace();
			return false; 
		}		 
 
		return true; 
6
CodeRank
This code example shows how to use the following methods:close, connect, getInputStream, getOutputStream
        if (mSocket != null) {
            return true; 
        } 
        Slog.i(TAG, "connecting...");
        try { 
            mSocket = new LocalSocket();
 
            LocalSocketAddress address = new LocalSocketAddress(
                "installd", LocalSocketAddress.Namespace.RESERVED);
 
            mSocket.connect(address);
 
            mIn = mSocket.getInputStream();
            mOut = mSocket.getOutputStream();
        } catch (IOException ex) {
            disconnect(); 
            return false; 
        } 
        return true; 
    } 

7
CodeRank
This code example shows how to use the following methods:connect, setReceiveBufferSize, setSendBufferSize
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
		 
		try { 
			receiver = new LocalSocket();
			receiver.connect(new LocalSocketAddress("com.vilkas04.ol-" + session_id));
			receiver.setReceiveBufferSize(500000);
			receiver.setSendBufferSize(500000);
			sender = lss.accept();
			sender.setReceiveBufferSize(500000);
			sender.setSendBufferSize(500000);
		} catch (IOException e2) {
			// TODO Auto-generated catch block 
			e2.printStackTrace();
		} 
	} 
	 
	public FileDescriptor getSenderFileDescriptor() {
		return sender.getFileDescriptor();
6
CodeRank
This code example shows how to use the following methods:close, connect, getOutputStream
	private static final String TAG = "SuRequest";
 
	public static void sendResult(Context context, AppDetails appDetails, String socketPath) {
        LocalSocket socket;
        try { 
            socket = new LocalSocket();
            socket.connect(new LocalSocketAddress(socketPath,
                    LocalSocketAddress.Namespace.FILESYSTEM));
 
            if (socket != null) {
                OutputStream os = socket.getOutputStream();
                String resultCode = appDetails.getPermissionCode();
                Log.d(TAG, "Sending result: " + resultCode + " for UID: " + appDetails.getUid());
                byte[] bytes = resultCode.getBytes("UTF-8");
                os.write(bytes);
                os.flush();
                os.close();
                socket.close();
            } 
        } catch (IOException e) {

6
CodeRank
This code example shows how to use the following methods:connect, setReceiveBufferSize, setSendBufferSize
 
	boolean initLoopback() 
	{		 
		releaseLoopback(); 
 
		receiver = new LocalSocket();
		try { 
			lss = new LocalServerSocket(localAddress);
			receiver.connect(new LocalSocketAddress(localAddress));
			receiver.setReceiveBufferSize(bufferSize);
			receiver.setSendBufferSize(bufferSize);
		} catch (IOException e) {
			Log.d(TAG, "Couldn't create local interthread connection", e);			
			return false; 
		}	 
		 
		try { 
			sender = lss.accept(); // blocks until a new connection arrives!
			sender.setReceiveBufferSize(bufferSize);
			sender.setSendBufferSize(bufferSize);
6
CodeRank
This code example shows how to use the following methods:connect, getInputStream, getOutputStream
     
    public Boolean connect(String path, int attemptsRemaining) {
        try { 
            Log.v(TAG, String.format("Connecting to domainsocket %s", path));
             
            socket = new LocalSocket();
            socket.connect(new LocalSocketAddress(path, LocalSocketAddress.Namespace.FILESYSTEM));
             
            socketWriter = new PrintWriter(socket.getOutputStream());
            socketReader = new BufferedReader(new InputStreamReader( socket.getInputStream()));
             
            Log.v(TAG, "Connection succesful");
             
            return true; 
        } 
        catch (IOException exception) {
            Log.v(TAG, String.format( "Connection failed, wait and retry %d attempts remaining"), exception);
            socket = null;
            return false; 
        } 
6
CodeRank

Related Android LocalSocket Questions & Answers:

See Code Examples for Android LocalSocket Methods: