-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPiScanner.java
More file actions
70 lines (60 loc) · 1.92 KB
/
Copy pathPiScanner.java
File metadata and controls
70 lines (60 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package parksmartdatabaseconnector;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
/**
*
* @author jorda
*/
public class PiScanner {
ServerSocket ss;
Socket socket;
InputStream inputStream;
DataInputStream in;
String message = "";
String input ="";
OutputStream outBS;
BufferedOutputStream outputS;
byte[] messageByte = new byte[1000];
boolean end = false;
public PiScanner(ServerSocket ss) throws IOException{
//ss = new ServerSocket(1619);
System.out.println("Awaiting connection from Pi");
socket = ss.accept();
System.out.println("Connection from " + socket);
in = new DataInputStream(socket.getInputStream());
OutputStream outputStream = socket.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
message = "this is jordan";
dataOutputStream.writeBytes(message);
dataOutputStream.flush();
}
public String getString() throws IOException{
System.out.println("waiting for string from " + socket);
boolean end = false;
while (!end){
int bytesRead = in.read(messageByte);
input += new String(messageByte, 0, bytesRead);
end = input.contains("}");
}
this.close();
return input;
}
public String getClientIP(){
return socket.getInetAddress().toString();
}
public void close() throws IOException{
//ss.close();
socket.close();
}
}