-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoilmakerController.java
More file actions
90 lines (71 loc) · 2.46 KB
/
Copy pathfoilmakerController.java
File metadata and controls
90 lines (71 loc) · 2.46 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import javax.swing.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.Scanner;
/**
* Created by Yufei Xu on 10/22/2016.
*implements network programming bits, application protocol
* users input
*/
public class foilmakerController{
static Socket socket;
public static String reply;
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
foilmakerView f = new foilmakerView();
int serverPort;
System.out.println("Please Enter the port number");
serverPort = scanner.nextInt();
String serverIP = "localhost";
try {
socket = new Socket(serverIP, serverPort);
} catch (IOException e) {
System.err.println("Error with IO:\n" + e.getMessage());
System.exit(3);
}
f.run();
}
public static void send(String inputLine)throws IOException{
PrintWriter outToServer = new PrintWriter(socket.getOutputStream(), true);
outToServer.println(inputLine);
}
public static void sendmessage(String inputLine) throws IOException {
PrintWriter outToServer = new PrintWriter(socket.getOutputStream(), true);
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(socket.getInputStream()));
outToServer.println(inputLine);
//reply = null;
//while(reply == null) {
//try {
//reply = inFromServer.readLine();
//System.out.println(reply);
//} catch (SocketTimeoutException e) {
// e.printStackTrace();
}
//}
//return reply;
//}
public static String recieve() throws IOException {
//socket.setSoTimeout(1);
String a = null;
while(a==null){
try {
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(socket.getInputStream()));
reply = inFromServer.readLine();
a = reply;
}catch (SocketTimeoutException e){
}
/*
try{
Thread.sleep(1);
}catch (InterruptedException e){
e.printStackTrace();
}
*/
}
//socket.setSoTimeout(1);
System.out.println(a);
return a;
}
}