-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.java
More file actions
46 lines (37 loc) · 1.18 KB
/
sample.java
File metadata and controls
46 lines (37 loc) · 1.18 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
//Blocking Classes
import java.net.Socket;
import java.net.ServerSocket;
//Non Blocking Classes
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Scanner;
import java.nio.ByteBuffer;
import java.io.PrintWriter;
//Misc Classes
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URL;
import java.net.URI;
import Network.Client.*;
class sample {
public static void main(String[] args) {
try {
InetAddress web = InetAddress.getByName("www.httpbin.org");
Socket sock = new Socket(web,80);
PrintWriter out = new PrintWriter(sock.getOutputStream());
Scanner in = new Scanner(sock.getInputStream());
out.write(" GET HTTP/1.0\r\nUser-Agent: Hello\r\n\r\n");
out.flush();
while(in.hasNextLine()) {
System.out.println(in.nextLine());
}
out.close();
in.close();
sock.close();
} catch (Exception e) {
//TODO: handle exception
}
}
}