Question with regard to Sockets

Discussion in 'Java' started by Atirya Yodha, Mar 7, 2004.

  1. Atirya Yodha

    Atirya Yodha Guest

    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
    Atirya Yodha, Mar 7, 2004
    #1
    1. Advertising

  2. Atirya Yodha wrote:
    > 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.
    >
    > 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
    >
    >
    Thomas Jollans, Mar 7, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerem38

    a simple question about sockets

    Jerem38, May 5, 2004, in forum: Java
    Replies:
    4
    Views:
    330
    Michiel Konstapel
    May 7, 2004
  2. Stefan Willmert

    Applets, Security, Sockets General Question

    Stefan Willmert, Jun 5, 2004, in forum: Java
    Replies:
    3
    Views:
    514
    Stefan Willmert
    Jun 5, 2004
  3. JKop
    Replies:
    28
    Views:
    1,690
    Richard Herring
    Sep 20, 2004
  4. Replies:
    13
    Views:
    511
    James Kanze
    May 27, 2006
  5. Catherine Moroney

    memory use with regard to large pickle files

    Catherine Moroney, Oct 15, 2008, in forum: Python
    Replies:
    3
    Views:
    297
    Aaron Brady
    Oct 19, 2008
Loading...

Share This Page