★ wanayoo — archive 1999 http://wdvl.com/Authoring/Scripting/Tutorial/java_connect_to_server.htmlNouvelle recherche | Portail wanayoo

Earn cash for Clicks! logo

internet.com
Join the free
WDVL newsletter!

home

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

Instantly look up a "techie" word using Webopedia!!


internet.com
e-commerce
WebDeveloper Network



Copyright 1999 internet.com Corporation. Legal Notices. Privacy Policy.

www.internet.com