-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPclient.java
More file actions
27 lines (19 loc) · 798 Bytes
/
TCPclient.java
File metadata and controls
27 lines (19 loc) · 798 Bytes
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
import java.io.*;
import java.net.*;
class TCPClient{
public static void main(String argv[]) throws Exception {
System.out.println('\n' + "Type a Word: ");
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
String word = inFromUser.readLine();
System.out.println();
String path = "GET /echo.php?message=" + word + " HTTP/1.0\r\n";
Socket clientSocket = new Socket("localhost",8888);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
out.println(path);
BufferedReader in = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));
String fromServer;
while((fromServer = in.readLine()) != null){
System.out.println(fromServer);
}
}
}