Solved

What is the advantage of URLConnection over Socket

Posted on 2001-06-22
7
437 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now