forked from hacker85/JavaLessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketLesson.java
More file actions
28 lines (26 loc) · 937 Bytes
/
SocketLesson.java
File metadata and controls
28 lines (26 loc) · 937 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
27
28
package network;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.util.Scanner;
public class SocketLesson {
public static void main(String[] args) {
try (Socket s = new Socket()) {
//s.connect(new InetSocketAddress(InetAddress.getLocalHost(), 8189));
//s.connect(new InetSocketAddress("india.colorado.edu", 13), 2000);
s.connect(new InetSocketAddress("google.com", 80), 2000);
InputStream inStream = s.getInputStream();
Scanner in = new Scanner(inStream);
while (in.hasNextLine()) {
String line = in.nextLine();
System.out.println(line);
}
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}