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;
13 import iotruntime.slave.IoTDeviceAddress;
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
19 * @author Ali Younid <ayounis @ uci.edu>
23 public final class IoTServerSocket {
26 * IoTTCP class properties
28 private ServerSocket sock;
34 public IoTServerSocket(IoTDeviceAddress iotDevAdd) throws UnknownHostException, IOException {
35 int iDstPort = iotDevAdd.getDestinationPortNumber();
36 sock = new ServerSocket(iDstPort);
43 public IoTTCP accept() throws UnknownHostException, IOException {
44 Socket recSock = sock.accept();
45 return new IoTTCP(recSock);
50 * setPerformancePreferences(int connectionTime, int latency, int bandwidth) method
52 public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) throws SocketException, IOException {
53 sock.setPerformancePreferences(connectionTime, latency, bandwidth);
57 * setReceiveBufferSize(int size) method
59 public void setReceiveBufferSize(int size) throws SocketException, IOException {
60 sock.setReceiveBufferSize(size);
64 * setReuseAddress(boolean on) method
66 public void setReuseAddress(boolean on) throws SocketException, IOException {
67 sock.setReuseAddress(on);
71 * setSoTimeout(int timeout) method
73 public void setSoTimeout(int timeout) throws SocketException, IOException {
74 sock.setSoTimeout(timeout);
80 public void close() throws SocketException, IOException {
85 * getLocalPort() method
87 public int getLocalPort() throws SocketException, IOException {
88 return sock.getLocalPort();
92 * getReceiveBufferSize() method
94 public int getReceiveBufferSize() throws SocketException, IOException {
95 return sock.getReceiveBufferSize();
99 * getReuseAddress() method
101 public boolean getReuseAddress() throws SocketException, IOException {
102 return sock.getReuseAddress();
106 * getSoTimeout() method
108 public int getSoTimeout() throws SocketException, IOException {
109 return sock.getSoTimeout();
115 public boolean isClosed() throws SocketException, IOException {
116 return sock.isClosed();
122 public boolean isBound() throws SocketException, IOException {
123 return sock.isBound();