Making classes final to make inheritance impossible
[iot2.git] / iotjava / iotrmi / Java / IoTSocketServer.java
1 package iotrmi.Java;
2
3 // Java libraries
4 import java.io.*;
5 import java.net.*;
6 import java.awt.*;
7 import java.util.*;
8
9
10 /** Class IoTSocketServer is a communication class
11  *  that extends IoTSocket. This is the server side.
12  *  <p>
13  *  Adapted from Java/C++ socket implementation
14  *  by Keith Vertanen
15  *  @see        <a href="https://www.keithv.com/software/socket/</a>
16  *
17  * @author      Rahmadi Trimananda <rtrimana @ uci.edu>
18  * @version     1.0
19  * @since       2016-08-17
20  */
21 public final class IoTSocketServer extends IoTSocket {
22
23         /**
24          * Class Properties
25          */
26         ServerSocket server;
27
28         /**
29          * Constructors
30          */
31         public IoTSocketServer(int _port) throws IOException
32         {
33                 super(_port);
34                 try {
35                         server = new ServerSocket(port, 100);
36                 }
37                 catch ( IOException e ) {
38                         e.printStackTrace();
39                 }
40     }
41
42
43         /**
44          * Establish connection
45          */
46         public void connect() throws IOException
47         {
48                 byte rev[] = new byte[1];
49                 rev[0] = 0;
50                 sock = server.accept();
51                 input = new BufferedInputStream(sock.getInputStream(), BUFFSIZE);
52                 output = new BufferedOutputStream(sock.getOutputStream(),BUFFSIZE);
53                 // now find out if we want reversed bytes
54                 input.read(rev);
55         }
56 }
57