🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #975

Re: need advice on Socket class

#975
From: Alan Shiers
Date: Sat, 29 Jun 2002 19:25
154 lines
5311 bytes
Hi John,

Following you'll see the class I'm using to create the connection with
the Socket class.

I tried your suggestion of just supplying "www.mss-webdesign.ca" but
that didn't work either. So, then I decided to look at some of the other
constructors for Socket and decided to include this one instead:
Socket(InetAddress host, int port)

After implementing the InetAddress object I still am no further ahead. 
I can connect using an IP string but not a URL string like:
http://www.mss-webdesign.ca

I've even reduced the string to just www.mss-webdesign.ca
and mss-webdesign.ca

Either way, I'm not connecting with the URL string. 

Perhaps by looking at my SocketOpener class you can see a problem?

Please advise,

Alan

*******************************************

Class SocketOpener is invoked like so:

Socket connection = SocketOpener.openSocket(internetAddress, portNumber,
timeoutPeriod);

*******************************************


import java.net.*;
import java.io.*;

public class SocketOpener implements Runnable
{
   private String host;
   private int port;
   private Socket socket;


   public SocketOpener(String aHost, int aPort)
   {
      socket = null;
      host = aHost;
      port = aPort;
   }
   /**
    * This is the method to call to establish a connection with a
timeout parameter.
    * @param A String IP or Web Address, an integer port number, and an
integer timeout value.
    */
   public static Socket openSocket(String aHost, int aPort, int timeout)
   {
      SocketOpener opener = new SocketOpener(aHost, aPort);
      Thread t = new Thread(opener);
      t.start();
      try
      {
         t.join(timeout);
      }
      catch(InterruptedException exception)
      {

      }
      return opener.getSocket();
   }

   /**
    * This class implements Runnable, therefore we must overwrite the
run() method.
    */
   public void run()
   {
      try
      {
         InetAddress address = null;
         address = InetAddress.getByName(host);
         socket = new Socket(host, port);
      }
      catch(IOException exception){}
   }

   /**
    * Get the Socket object.
    * @return Socket
    */
   public Socket getSocket()
   {
      return socket;
   }
}

"John McGrath [TeamB]" wrote:
> 
> On Sat, 29 Jun 2002 10:35:41 -0400, Alan Shiers wrote:
> 
> > I've created a client/server application using a Socket on the
> > client-side.  The constructor I'm using for it is:
> > Socket(String host, int port)
> 
> > So, theoretically, I thought, I should be able to replace now the
> > IP address 192.168.0.196 with the URL: http://www.mss-webdesign.ca
> > on port 5000 and still be able to connect.
> 
> The argument to the Socket constructor is a host name, not a URL or a
> URL string.  The URL specifies a host name, but it also specifies a
> protocol and other information which does not apply.  Your program is
> using an IP socket, but it is not using the protocol "http".
> 
> Try changing the argument to "www.mss-webdesign.ca".
> 
> --
> Regards,
> 
> John McGrath [TeamB]
> 
> ---------------------------------------------------
> Before sending me e-mail, please read:
>     http://www.JPMcGrath.net/newsgroups/e-mail.html


"John McGrath [TeamB]" wrote:
> 
> On Sat, 29 Jun 2002 10:35:41 -0400, Alan Shiers wrote:
> 
> > I've created a client/server application using a Socket on the
> > client-side.  The constructor I'm using for it is:
> > Socket(String host, int port)
> 
> > So, theoretically, I thought, I should be able to replace now the
> > IP address 192.168.0.196 with the URL: http://www.mss-webdesign.ca
> > on port 5000 and still be able to connect.
> 
> The argument to the Socket constructor is a host name, not a URL or a
> URL string.  The URL specifies a host name, but it also specifies a
> protocol and other information which does not apply.  Your program is
> using an IP socket, but it is not using the protocol "http".
> 
> Try changing the argument to "www.mss-webdesign.ca".
> 
> --
> Regards,
> 
> John McGrath [TeamB]
> 
> ---------------------------------------------------
> Before sending me e-mail, please read:
>     http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <3D1E099E.AE32ACA5@hfx.eastlink.ca>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!news.tele.dk!small.news.tele.dk!208.49.253.98!newsfeed.news2me.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews
References: <3D1DC5BD.D42C0685@hfx.eastlink.ca> <MPG.1787a1ffb01ea2b98b778@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,ca7b36f31cbe071c
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-06-29 11:33:36 PST
Message-ID: <3D1E099E.AE32ACA5@hfx.eastlink.ca>
Date: Sat, 29 Jun 2002 15:25:18 -0400
From: Alan Shiers <ashiers@hfx.eastlink.ca>
Organization: Mustard Seed Software
X-Mailer: Mozilla 4.78 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.api
Subject: Re: need advice on Socket class
References: <3D1DC5BD.D42C0685@hfx.eastlink.ca> <MPG.1787a1ffb01ea2b98b778@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 24.222.101.2
X-Trace: dnews 1025374970 24.222.101.2 (29 Jun 2002 11:22:50 -0700)
Lines: 154
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!news.tele.dk!small.news.tele.dk!208.49.253.98!newsfeed.news2me.com!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews