Adding config file for sharing.
[iot2.git] / iotjava / iotrmi / Java / IoTSocketClient.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 IoTSocketClient is a communication class
11  *  that extends IoTSocket. This is the client 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 IoTSocketClient extends IoTSocket {
22
23         /**
24          * Default constructor
25          */
26         public IoTSocketClient(int _port, String _address, int rev) throws IOException
27                 {
28                 super(_port);
29                 try {
30                         sock = new Socket( InetAddress.getByName(_address), port );
31                         input = new BufferedInputStream(sock.getInputStream(), BUFFSIZE);
32                         output = new BufferedOutputStream(sock.getOutputStream(),BUFFSIZE);
33                 }
34                 catch ( IOException e ) {
35                         e.printStackTrace();
36                 }
37                 // now we want to tell the server if we want reversed bytes or not
38                 output.write(rev);
39                 output.flush();
40         }
41
42         /**
43          * Additional constructor
44          */
45         public IoTSocketClient(int _localPort, int _port, String _address, int rev) throws IOException
46         {
47                 super(_localPort, _port);
48                 try {
49                         sock = new Socket( InetAddress.getByName(_address), 
50                                                 port, InetAddress.getByName(_address), localPort );
51                         input = new BufferedInputStream(sock.getInputStream(), BUFFSIZE);
52                         output = new BufferedOutputStream(sock.getOutputStream(),BUFFSIZE);
53                 }
54                 catch ( IOException e ) {
55                         e.printStackTrace();
56                 }
57                 // now we want to tell the server if we want reversed bytes or not
58                 output.write(rev);
59                 output.flush();
60         }
61 }