-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clientsocket.java
73 lines (39 loc) · 1.18 KB
/
Clientsocket.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package testPrint;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.net.InetAddress;
import java.util.Arrays;
public class Clientsocket {
public static void main(String args[]) throws UnknownHostException, IOException
{
try
{
System.out.println("socket is connected");
InetAddress lookup[] = InetAddress.getAllByName("www.njit.edu");
for(int h = 0; h < lookup.length; h++)
System.out.println(lookup[h]);
Socket example = new Socket(lookup[0], 80);
example.getOutputStream().write(("GET " +"/ " + "HTTP/1.1\r\n" + "Host: " + "www.njit.edu" + "\r\n" + "Connection: close\r\n\r\n").getBytes("UTF-8"));
int size = 500;
byte storer[] = new byte[size];
int start = 0;
int end = size;
boolean checker = true;
int s = 0;
int r = 0;
while(s!=-1)
{
example.getInputStream().skip(start);
s = example.getInputStream().read(storer,0 , size);
for(int i = 0; i < s; i++)
System.out.print((char)storer[i]);
start = start+s;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}