-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTPClient.java
35 lines (29 loc) · 1.2 KB
/
HTTPClient.java
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
import java.net.*;
import java.io.*;
import java.util.Scanner;
public class HTTPClient{
public static void main(String[] args){
Socket socket = null;
int serverPort = 5000;
Scanner sc = new Scanner(System.in);
try{
socket = new Socket ("127.0.0.1", serverPort);
DataInputStream inCliente = new DataInputStream(socket.getInputStream());
DataOutputStream outCliente = new DataOutputStream(socket.getOutputStream());
while(true){
System.out.println("-----------------------------------------------");
System.out.println("SERVIDOR HTTP AGUARDANDO REQUEST...");
System.out.println("-----------------------------------------------");
String request = sc.nextLine();
outCliente.writeUTF(request);
String data = inCliente.readUTF();
System.out.println(data);
System.out.println("Conexao ao host perdida.");
}
}catch (UnknownHostException ex){
ex.printStackTrace();
}catch (IOException ex){
ex.printStackTrace();
}
}
}