aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Creating a new Socket and parameters to the Socket Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Creating a new Socket and parameters to the Socket Constructor" Watch "Creating a new Socket and parameters to the Socket Constructor" New topic
Author

Creating a new Socket and parameters to the Socket Constructor

John McDowell
Greenhorn

Joined: Jun 14, 2014
Posts: 26
Socket socket = new Socket("127.0.0.1",5000);

HeadFirst Java says that the ip address that I have put in double quotes can be replaced by the domain name.Could somebody tell me how that would work.With a real life example. Please don't redirect me to some site with tons of api descriptions. Just give me a nice example, like the examples in HFJ. Can I connect to the Google server and send a search query as a String to it using printWriter object
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
Yes, you can, but not on port 5000, and not quite as easily as you seem to assume. HTTP generally uses port 80 (or port 443 for HTTPS), and you would need to send and receive HTTP over the socket. So it's not like a web browser where you can simply enter the URL and get back a web page.

But you don't have to implement all that - the java.net package has classes that do all this for you, like URL, URLConnection and HttpURLConnection.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a new Socket and parameters to the Socket Constructor