JavaSocket: A secret class in Java & nbsp; Socket programming, Javascript tutorial
Introduction
The Java platform implements Socket in the java.net package. In this article, we will use the following three classes in the Java.net package to work:
URLConnection
Socket
ServerSocket
There are more classes in the java.net package, but these are the most common ones. Let's start with URLConnection, this class provides the method of using Socket in your java code without understanding the underlying mechanism of Socket.
You can use sockets without even trying.
To connect to a URL, follow these steps:
Create a URLConnection
Configure it using different setter Methods
Connect to URLConnection
Interaction with different getter Methods
Next, we will use some examples to demonstrate how to use URLConnection to request a document from a server.
URLClient class
We will start with the structure of the URLClient class.
Import java. io .*;
Import java.net .*;
Public class URLClient {
Protected URLConnection connection;
Public static void main (String [] args ){}
Public String getDocumentAt (String urlString ){}
}
Note: you must first import the java.net and java. io packages.
[1] [2] [3] Next page