A
Atirya Yodha
Hi All,
I have a few questions regarding sockets :
1. Is there any distinction between
ServerSocket and Socket other than :
a) Socket is used by the client to initiate
connections to other hosts and ServerSocket
used by the server via which it can listen to
incoming TCP connections
Does that mean that using Socket a process can't
listen for incoming connections and using a ServerSocket
can't open a connection to another host.
What was the real motive behind this separation ?
2. Does Java support the use of Raw Sockets ?
I wanted to try out a 'ping' program in Java,
wherein I can construct a ICMP Header myself
and its data bits. But is it possible to do using
java.net.Socket where I can directly manipulate the
underlying bits ?
3. How do I make Sockets work with Proxy Servers , ie ,
suppose I can access the internet only through the proxy server,
then how can I make connections to certain web servers ( an NTP
server for instance ) through the proxy server . I tried
Properties prop = System.getProperties();
prop.put("http.proxyHost", "<my proxy server address>");
prop.put("http.proxyPort", "<port>");
But when I try to do :
Socket so = new Socket(machine, 13);
I get a java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
I tried with different NTP servers listed in :
http://www.eecis.udel.edu/~mills/ntp/clock1a.html
but in vain.
Thanks a lot for your time.
- Atirya
I have a few questions regarding sockets :
1. Is there any distinction between
ServerSocket and Socket other than :
a) Socket is used by the client to initiate
connections to other hosts and ServerSocket
used by the server via which it can listen to
incoming TCP connections
Does that mean that using Socket a process can't
listen for incoming connections and using a ServerSocket
can't open a connection to another host.
What was the real motive behind this separation ?
2. Does Java support the use of Raw Sockets ?
I wanted to try out a 'ping' program in Java,
wherein I can construct a ICMP Header myself
and its data bits. But is it possible to do using
java.net.Socket where I can directly manipulate the
underlying bits ?
3. How do I make Sockets work with Proxy Servers , ie ,
suppose I can access the internet only through the proxy server,
then how can I make connections to certain web servers ( an NTP
server for instance ) through the proxy server . I tried
Properties prop = System.getProperties();
prop.put("http.proxyHost", "<my proxy server address>");
prop.put("http.proxyPort", "<port>");
But when I try to do :
Socket so = new Socket(machine, 13);
I get a java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
I tried with different NTP servers listed in :
http://www.eecis.udel.edu/~mills/ntp/clock1a.html
but in vain.
Thanks a lot for your time.
- Atirya