[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/io SocketConnectionFacade.java,1.2,1
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-09-27 21:07:41
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22035/src/java/net/sf/asterisk/io Modified Files: SocketConnectionFacade.java SocketConnectionFacadeImpl.java Log Message: Added getLocalAddress(), getLocalPort(), getRemoteAddress() and getRemotePort() to AGIRequest (AJ-14) Index: SocketConnectionFacade.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/io/SocketConnectionFacade.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SocketConnectionFacade.java 23 Jun 2005 22:06:10 -0000 1.2 +++ SocketConnectionFacade.java 27 Sep 2005 21:07:26 -0000 1.3 @@ -17,6 +17,7 @@ package net.sf.asterisk.io; import java.io.IOException; +import java.net.InetAddress; /** * The SocketConnectionFacade provides read and write operation for @@ -73,4 +74,36 @@ public interface SocketConnectionFacade * server */ boolean isConnected(); + + /** + * Returns the local address this socket connection. + * + * @return the local address this socket connection. + * @since 0.2 + */ + InetAddress getLocalAddress(); + + /** + * Returns the local port of this socket connection. + * + * @return the local port of this socket connection. + * @since 0.2 + */ + int getLocalPort(); + + /** + * Returns the remote address of this socket connection. + * + * @return the remote address of this socket connection. + * @since 0.2 + */ + InetAddress getRemoteAddress(); + + /** + * Returns the remote port of this socket connection. + * + * @return the remote port of this socket connection. + * @since 0.2 + */ + int getRemotePort(); } Index: SocketConnectionFacadeImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/io/SocketConnectionFacadeImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- SocketConnectionFacadeImpl.java 23 Jun 2005 22:06:10 -0000 1.2 +++ SocketConnectionFacadeImpl.java 27 Sep 2005 21:07:26 -0000 1.3 @@ -19,30 +19,44 @@ package net.sf.asterisk.io; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.net.InetAddress; import java.net.Socket; +/** + * Default implementation of the SocketConnectionFacade interface using java.io. + * + * @author srt + * @version $Id$ + */ public class SocketConnectionFacadeImpl implements SocketConnectionFacade { private final Socket socket; private final BufferedReader reader; private final BufferedWriter writer; - + public SocketConnectionFacadeImpl(String host, int port) throws IOException { - this.socket = new Socket(host, port); - this.reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); - this.writer = new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream())); + this(new Socket(host, port)); } - + SocketConnectionFacadeImpl(Socket socket) throws IOException { + InputStream inputStream; + OutputStream outputStream; + + inputStream = socket.getInputStream(); + outputStream = socket.getOutputStream(); + this.socket = socket; - this.reader = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); - this.writer = new BufferedWriter(new OutputStreamWriter(this.socket.getOutputStream())); + + this.reader = new BufferedReader(new InputStreamReader(inputStream)); + this.writer = new BufferedWriter(new OutputStreamWriter(outputStream)); } - + public String readLine() throws IOException { return reader.readLine(); @@ -67,4 +81,24 @@ public class SocketConnectionFacadeImpl { return socket.isConnected(); } + + public InetAddress getLocalAddress() + { + return socket.getLocalAddress(); + } + + public int getLocalPort() + { + return socket.getLocalPort(); + } + + public InetAddress getRemoteAddress() + { + return socket.getInetAddress(); + } + + public int getRemotePort() + { + return socket.getPort(); + } } |