Solved

What is the advantage of URLConnection over Socket

Posted on 2001-06-22
7
459 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

630 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