more changes
[IRC.git] / Robust / src / ClassLibrary / SocketJava.java
1 public class Socket {
2     /* File Descriptor */
3     int fd;
4     SocketInputStream sin;
5     SocketOutputStream sout;
6
7     public Socket() {
8         sin=new SocketInputStream(this);
9         sout=new SocketOutputStream(this);
10     }
11
12     public InputStream getInputStream() {
13         return sin;
14     }
15
16     public OutputStream getOutputStream() {
17         return sout;
18     }
19
20     public Socket(String host, int port) {
21         InetAddress address=InetAddress.getByName(host);
22         fd=nativeBind(address.getAddress(), port);
23         nativeConnect(fd, address.getAddress(), port);
24     }
25     
26     public Socket(InetAddress address, int port) {
27         fd=nativeBind(address.getAddress(), port);
28         nativeConnect(fd, address.getAddress(), port);
29     }
30
31     public static native int nativeBind(byte[] address, int port);
32
33     public static native int nativeConnect(int fd, byte[] address, int port);
34     
35     int setFD(int filed) {
36         fd=filed;
37     }
38
39     public int read(byte[] b) {
40         return nativeRead(b);
41     }
42     public void write(byte[] b) {
43         nativeWrite(b);
44     }
45
46     private native int nativeRead(byte[] b);
47     private native void nativeWrite(byte[] b);
48     private native void nativeClose();
49
50     public void close() {
51         nativeClose();
52     }
53 }