Code example for LocalSocket

Methods: close, connect, setReceiveBufferSize, setSendBufferSize

0
	private LocalServerSocket lss = null;
	private LocalSocket receiver, sender = null;
	 
	public void prepare() throws IllegalStateException,IOException { 
		 
		receiver = new LocalSocket();
		try { 
			lss = new LocalServerSocket("librtp-"+id);
			receiver.connect(new LocalSocketAddress("librtp-"+id));
			receiver.setReceiveBufferSize(500000);
			receiver.setSendBufferSize(500000);
			sender = lss.accept();
			sender.setReceiveBufferSize(500000);
			sender.setSendBufferSize(500000);
			id++;
		} catch (IOException e1) {
			MyLog.e("What ? It cannot be !!"); 
			return; 
		} 
		 
		setOutputFile(sender.getFileDescriptor());
		 
		try { 
			super.prepare(); 
		} catch (IllegalStateException e) {
			closeSockets(); 
			throw e;
		} catch (IOException e) {
			closeSockets(); 
			throw e;
		} 
		 
	} 
	 
	public InputStream getInputStream() {
		 
		InputStream out = null;
		 
		try { 
			out = receiver.getInputStream();
		} catch (IOException e) {
		} 
 
		return out;
		 
	} 
 
	 
	public void stop() { 
		super.stop(); 
		closeSockets(); 
	} 
	 
	private void closeSockets() { 
		try { 
			lss.close();
			sender.close();
			receiver.close();
		} 
		catch (IOException e) {
			MyLog.e("Error while attempting to close local sockets"); 
		} 
		lss = null; sender = null; receiver = null;