Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Connecting to a Server

  • Connecting to a server is extremely easy with Java's built in socket classes for communicating via HTTP. You will recall from day two how we connected to a web server using the GET and POST methods of HTTP. Well in java, the process is exactly the same Specifically, you create a socket object which connects to a server somewhere on the web using syntax such as the following:

    Socket s = new Socket("url", portNumber);

  • Thus, the following code would open a socket to www.extropia.com on port 80:

    Socket s = new Socket("www.extropia.com", 80);

  • So what happens if your application cannot reach the server specified? Well, it is essential that you place your networking within a try block which catches several errors such as UnknownHostException, MalformedURLException, and IOException.

Additional Resources:

Network Programming in Java
Table of Contents
Getting Information from a Remote Site


Up to => Home / Authoring / Scripting / Tutorial




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers