Solved

What is the advantage of URLConnection over Socket

Posted on 2001-06-22
7
442 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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