blob: 78a367b4d6780556e8dd34d24d26c09007d161b2 (
plain)
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
|
import java.net.*;
public class SocketTest
{
public static void main(String args[])
{
try {
Socket socket = new Socket("www.hungry.com", 80);
InetAddress remote = socket.getInetAddress();
InetAddress local = socket.getLocalAddress();
int rport = socket.getPort();
int lport = socket.getLocalPort();
socket.setSoTimeout(socket.getSoTimeout());
socket.setTcpNoDelay(socket.getTcpNoDelay());
int linger = socket.getSoLinger();
if (-1 != linger)
socket.setSoLinger(true, linger);
else
socket.setSoLinger(false, 0);
String socketString = socket.toString();
if (null == socketString)
throw new Exception("toString() failed");
socket.close();
System.out.println("PASSED: new Socket()" + socketString);
} catch (Exception e) {
System.out.println("FAILED: " + e);
}
}
}
|