Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is the advantage of URLConnection over Socket

Posted on 2001-06-22
7
Medium Priority
?
464 Views
Last Modified: 2012-06-27
hi

What is the advantage of URLConnection over Socket?.

thanks
0
Comment
Question by:mmsreddy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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 300 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

688 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