Solved

What is the advantage of URLConnection over Socket

Posted on 2001-06-22
7
451 Views
Last Modified: 2012-06-27
hi

What is the advantage of URLConnection over Socket?.

thanks
0
Comment
Question by:mmsreddy
7 Comments
 
LVL 3

Expert Comment

by:superschlonz
ID: 6218284
It's subclasses implement a protocol, for example HttpUrlConnection.
If you use Socket you have to implement the protocol yourself.

If you just want to get a page from a Webserver you can use a Socket
and implement the HTTP yourself or you can use the following code:

URLConnection conn = new URL( "http://myserver/mypage.html" ).openConnection();
// perhaps set some properties of URLConnection...
InputStream is = conn.getInputStream();
0
 
LVL 1

Expert Comment

by:goldwarlock
ID: 6219606
URLConnection is based on HTTP protocol
and Socket - pure TCP/IP socket

Useng 1st you have lots of advantages - easy access etc.
but no customization
using 2nd you can do almost everything - but averything by yourself

visit my site
www.xanga.com/goldwarlock
0
 
LVL 1

Expert Comment

by:goldwarlock
ID: 6219618
btw: visit my site
www.xanga.com/goldwarlock
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6220196
And from the server side, you need appropriate server to handle requests coming through URLConnection (e.g. Web server for HttpURLConnection), while it's pretty easy to create server for socket connections (well, taking protocol issues out)

Igor Bazarny,
Brainbench MVP for Java 1
www.brainbench.com
0
 
LVL 1

Accepted Solution

by:
sumeetsh earned 100 total points
ID: 6230000
hi

Socket
=======
This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines.

The actual work of the socket is performed by an instance of the SocketImpl class. An application, by changing the socket factory that creates the socket implementation, can configure itself to create sockets appropriate to the local firewall.

URLConnection
==============
URLs and URLConnections provide a relatively high-level mechanism for accessing resources on the Internet.

The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL. In general, creating a connection to a URL is a multistep process:

0
 

Author Comment

by:mmsreddy
ID: 6252310
Hi

     how to connect other than 80 port without using the sockets?. is it possible to connect with URLConnection?.
if yes, how?. i want connect port 1900, but i do't want use socket.

thanks
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 6262059
Hi,
> how to connect other than 80 port without using the sockets?

List port at URL construction time. Use multiarg constructor or http://host.domain:port/path/file.html syntax.

Regards,
Igor Bazarny
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
by zero exception 10 70
What's wrong with this code? 4 34
maven disable workspace resolution 1 38
passing enum to a method 4 35
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question