Question with regard to Sockets

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
 
T

Thomas Jollans

Atirya said:
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 ?
All TCP communication runs thru Socket and ServerSocket is just for
listening.
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 ?
It looks like Socket is just for TCP and DatagramSpcket is just for UDP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top