Preparing Makefiles, stub, skeleton, config files, etc. for porting LifxLightBulb...
[iot2.git] / iotjava / iotruntime / IoTServerSocket.java
1 package iotruntime;
2
3 // Java packages
4 import java.io.IOException;
5 import java.net.UnknownHostException;
6 import java.net.SocketException;
7 import java.net.Socket;
8 import java.net.InetAddress;
9 import java.net.ServerSocket;
10 import java.io.InputStream;
11 import java.io.OutputStream;
12
13 import iotruntime.slave.IoTDeviceAddress;
14
15 /** Class IoTServerSocket is a wrapper class that provides
16  *  minimum interfaces for user to interact with IoT
17  *  devices in our system using ServerSockets
18  *
19  * @author      Ali Younid <ayounis @ uci.edu>
20  * @version     1.0
21  * @since       2016-05-03
22  */
23 public final class IoTServerSocket {
24
25     /**
26      * IoTTCP class properties
27      */
28     private ServerSocket sock;
29
30
31     /**
32      * Class constructor
33      */
34     public IoTServerSocket(IoTDeviceAddress iotDevAdd) throws UnknownHostException, IOException {
35         int iDstPort = iotDevAdd.getDestinationPortNumber();
36         sock = new ServerSocket(iDstPort);
37     }
38
39
40     /**
41     * accept() method
42     */
43     public IoTTCP accept() throws UnknownHostException, IOException {
44         Socket recSock = sock.accept();
45         return new IoTTCP(recSock);
46     }
47
48
49     /**
50     * setPerformancePreferences(int connectionTime, int latency, int bandwidth) method
51     */
52     public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) throws SocketException, IOException {
53         sock.setPerformancePreferences(connectionTime, latency, bandwidth);
54     }
55
56     /**
57     * setReceiveBufferSize(int size) method
58     */
59     public void setReceiveBufferSize(int size) throws SocketException, IOException {
60         sock.setReceiveBufferSize(size);
61     }
62
63     /**
64     * setReuseAddress(boolean on) method
65     */
66     public void setReuseAddress(boolean on) throws SocketException, IOException {
67         sock.setReuseAddress(on);
68     }
69
70     /**
71     * setSoTimeout(int timeout) method
72     */
73     public void setSoTimeout(int timeout) throws SocketException, IOException {
74         sock.setSoTimeout(timeout);
75     }
76
77     /**
78     * close() method
79     */
80     public void close() throws SocketException, IOException {
81         sock.close();
82     }
83
84     /**
85     * getLocalPort() method
86     */
87     public int getLocalPort() throws SocketException, IOException {
88         return sock.getLocalPort();
89     }
90
91     /**
92     * getReceiveBufferSize() method
93     */
94     public int getReceiveBufferSize() throws SocketException, IOException {
95         return sock.getReceiveBufferSize();
96     }
97
98     /**
99     * getReuseAddress() method
100     */
101     public boolean getReuseAddress() throws SocketException, IOException {
102         return sock.getReuseAddress();
103     }
104
105     /**
106     * getSoTimeout() method
107     */
108     public int getSoTimeout() throws SocketException, IOException {
109         return sock.getSoTimeout();
110     }
111
112     /**
113     * isClosed() method
114     */
115     public boolean isClosed() throws SocketException, IOException {
116         return sock.isClosed();
117     }
118
119     /**
120     * isBound() method
121     */
122     public boolean isBound() throws SocketException, IOException {
123         return sock.isBound();
124     }
125
126 }