summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Cleeland <chris.cleeland@gmail.com>1997-01-30 04:32:59 +0000
committerChris Cleeland <chris.cleeland@gmail.com>1997-01-30 04:32:59 +0000
commit0025c62efcf3f7e3a3afbee16b677fb701aec394 (patch)
tree6b7cb7a98da2de4002d09fe48be886243d41956c
parent05e49f31d2cdb632de0eb56c6b7689696c3468a8 (diff)
downloadATCD-0025c62efcf3f7e3a3afbee16b677fb701aec394.tar.gz
Made changes resulting from working through a simple Logger example.
Modified Files: Makefile Readme SOCKConnector.java SOCKStream.java Added Files: INETAddr.java
-rw-r--r--java/src/INETAddr.java99
-rw-r--r--java/src/Makefile3
-rw-r--r--java/src/Readme5
-rw-r--r--java/src/SOCKConnector.java12
-rw-r--r--java/src/SOCKStream.java14
5 files changed, 122 insertions, 11 deletions
diff --git a/java/src/INETAddr.java b/java/src/INETAddr.java
new file mode 100644
index 00000000000..d749e200658
--- /dev/null
+++ b/java/src/INETAddr.java
@@ -0,0 +1,99 @@
+/*************************************************
+ *
+ * = PACKAGE
+ * ACE.SOCK_SAP
+ *
+ * = FILENAME
+ * INETAddr.java
+ *
+ *@author Chris Cleeland
+ *
+ *************************************************/
+package ACE.SOCK_SAP;
+
+import java.io.*;
+import java.net.*;
+import ACE.OS.*;
+
+/**
+ * <hr>
+ * <p><b>TITLE</b><br>
+ * Defines an endpoint of a connection, encapsulating host and port.
+ * This is only a part-way implementation of C++ ACE's ACE_INET_Addr.
+ *
+ * <p><b>LIMITATIONS</b><br>
+ * Currently the class is very limited in its capabilities; it will
+ * be expanded in future revisions of ACE.
+ */
+public class INETAddr // extends Addr
+{
+ private InetAddress addr_;
+ private int port_ = 0;
+ /**
+ */
+ public INETAddr ()
+ {
+ // Do nothing constructor
+ }
+
+ /**
+ * Create an INETAddr from a port/hostname
+ *@param port port number to connect with server at
+ *@param hostname hostname of the server
+ */
+ public INETAddr (int port, String hostname) throws UnknownHostException
+ {
+ super();
+ port_ = port;
+ addr_ = InetAddress.getByName(hostname);
+ // Should really use getAllByName(),
+ // but I don't think we do that in
+ // C++ ACE, even.
+ }
+
+ /**
+ * Create an INETAddr from an address.
+ * @param address an address in the form "ip-number:port-number", <em>e.g.</em> <pre>tango.cs.wustl.edu:1234</pre> or <pre>128.252.166.57:1234</pre>; if no ':' is present address is assumed to be <b>INADDR_ANY</b> and address contains only the port number
+ * @throws UnknownHostException
+ */
+ public INETAddr (String address) throws UnknownHostException
+ {
+ int colon = address.indexOf(':');
+ if (colon != 0)
+ {
+ addr_ = InetAddress.getByName(address.substring(0, colon));
+ address = address.substring(colon+1);
+ }
+
+ port_ = Integer.parseInt(address);
+ }
+
+ /**
+ * Return the name of the host.
+ */
+ public String getHostName()
+ {
+ return addr_.getHostName();
+ }
+
+ /**
+ * Return the dotted Internet address.
+ */
+ public String getHostAddr()
+ {
+ return addr_.toString();
+ }
+
+ /**
+ * Return the port number.
+ */
+ public int getPortNumber()
+ {
+ return port_;
+ }
+
+ public String toString()
+ {
+ return getHostAddr() + Integer.toString(port_);
+ }
+}
diff --git a/java/src/Makefile b/java/src/Makefile
index d4066ee0aa4..be0871f39db 100644
--- a/java/src/Makefile
+++ b/java/src/Makefile
@@ -58,7 +58,7 @@ pkg_os = \
os: $(addsuffix .java,$(pkg_os))
$(COMPILE.java)
-
+
pkg_concurrency = \
Condition \
Mutex \
@@ -102,6 +102,7 @@ reactor: asx_timestuff $(addsuffix .java,$(pkg_reactor))
$(COMPILE.java)
pkg_socksap = \
+ INETAddr \
SOCKStream \
SOCKAcceptor \
SOCKConnector
diff --git a/java/src/Readme b/java/src/Readme
index 1844a7db881..73220d55de4 100644
--- a/java/src/Readme
+++ b/java/src/Readme
@@ -6,13 +6,12 @@ The Makefile has been worked over severely, and it now REQUIRES GNU
Make. The makefile is still a little rough, and will definitely
evolve.
-Suggestsions are welcome at cleeland@cs.wustl.edu or pjain@cs.wustl.edu.
+Suggestions are welcome at cleeland@cs.wustl.edu or pjain@cs.wustl.edu.
Also, TimeValue moved from the ACE.Reactor to ACE.ASX package to break
up some circular dependency problems.
----------
The documentation for Java ACE has not been included in the release
but can be automatically generated by typing "make doc" in the src
directory. Note that the gif images needed by the documentaion ARE
-included in the release. \ No newline at end of file
+included in the release.
diff --git a/java/src/SOCKConnector.java b/java/src/SOCKConnector.java
index 8b94b22db47..fd1fcb6d685 100644
--- a/java/src/SOCKConnector.java
+++ b/java/src/SOCKConnector.java
@@ -60,4 +60,16 @@ public class SOCKConnector
{
sockStream.socket (new Socket (hostname, port));
}
+
+ /**
+ * Connect to the server.
+ *@param sockStream SOCK Stream to use for the connection
+ *@param addr INETAddr instance specifying host/port
+ */
+ public void connect (SOCKStream sockStream,
+ INETAddr addr) throws SocketException, IOException
+ {
+ sockStream.socket (new Socket (addr.getHostName(),
+ addr.getPortNumber()));
+ }
}
diff --git a/java/src/SOCKStream.java b/java/src/SOCKStream.java
index d944a8fc8d2..4aa0294550e 100644
--- a/java/src/SOCKStream.java
+++ b/java/src/SOCKStream.java
@@ -46,13 +46,13 @@ public class SOCKStream
*@param s Socket associated with the SOCK Stream.
*/
public void socket (Socket s) throws IOException
- {
- // Note that if s is not a valid socket or is null, the
- // following calls will throw exceptions
- this.iStream_ = new DataInputStream (s.getInputStream ());
- this.oStream_ = new PrintStream (s.getOutputStream ());
- this.socket_ = s;
- }
+ {
+ this.socket_ = s;
+ // Note that if s is not a valid socket or is null, the
+ // following calls will throw exceptions
+ this.iStream_ = new DataInputStream (s.getInputStream ());
+ this.oStream_ = new PrintStream (s.getOutputStream ());
+ }
/* Get the underlying Socket.
*@return the underlying socket