start of new file
[IRC.git] / Robust / src / ClassLibrary / Socket.java
index ddfc8a9bf817b85b07f3ed81e583a7fdeaeee8ba..452e395e4e1890c0fe204dce5e194b47368534cf 100644 (file)
@@ -3,8 +3,20 @@ public class Socket {
     external flag IOPending;    
     /* File Descriptor */
     int fd;
+    private SocketInputStream sin;
+    private SocketOutputStream sout;
     
     public Socket() {
+       sin=new SocketInputStream(this);
+       sout=new SocketOutputStream(this);
+    }
+
+    public InputStream getInputStream() {
+       return sin;
+    }
+
+    public OutputStream getOutputStream() {
+       return sout;
     }
 
     public Socket(String host, int port) {
@@ -18,9 +30,20 @@ public class Socket {
        nativeConnect(fd, address.getAddress(), port);
     }
 
+    public void connect(String host, int port) {
+       InetAddress address=InetAddress.getByName(host);
+       fd=nativeBind(address.getAddress(), port);
+       nativeConnect(fd, address.getAddress(), port);
+    }
+
+    public void connect(InetAddress address, int port) {
+       fd=nativeBind(address.getAddress(), port);
+       nativeConnect(fd, address.getAddress(), port);
+    }
+
     public static native int nativeBind(byte[] address, int port);
 
-    public static native int nativeConnect(int fd, byte[] address, int port);
+    public native int nativeConnect(int fd, byte[] address, int port);
     
     int setFD(int filed) {
        fd=filed;
@@ -30,11 +53,16 @@ public class Socket {
        return nativeRead(b);
     }
     public void write(byte[] b) {
-       nativeWrite(b);
+       nativeWrite(b, 0, b.length);
+    }
+
+    public void write(byte[] b, int offset, int len) {
+       nativeWrite(b, offset, len);
     }
 
+    private native void nativeBindFD(int fd);
     private native int nativeRead(byte[] b);
-    private native void nativeWrite(byte[] b);
+    private native void nativeWrite(byte[] b, int offset, int len);
     private native void nativeClose();
 
     public void close() {