-
Notifications
You must be signed in to change notification settings - Fork 0
/
Httpserver.java
58 lines (52 loc) · 1.41 KB
/
Httpserver.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package app;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
public class Httpserver {
DataOutputStream webpage;
DataInputStream ipaddres;
Socket Client;
FileReader page;
BufferedReader writedomain;
Scanner s;
static ServerSocket sock;
public final static int port = 6999;
public void net(){
try{
System.out.println("Connecting....");
Socket httpclient = sock.accept();
System.out.println("Connected to client");
ipaddres = new DataInputStream(httpclient.getInputStream());
String ip = ipaddres.readUTF();
switch(ip){
case "32.37.14.143":
webpage = new DataOutputStream(httpclient.getOutputStream());
writedomain = new BufferedReader(new FileReader("Client.txt"));
String paagedata = writedomain.readLine();
System.out.println("the data in Client.txt file is : "+paagedata);
webpage.writeUTF(paagedata);
webpage.flush();
System.out.print("Send data.");
break;
}
}catch(IOException f){}
}
public static void main(String args[]){
Httpserver jx = new Httpserver();
try {
sock = new ServerSocket(port);
System.out.println("HTTP SERVER STARTED");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(true){
jx.net();
}
}
}