Home » net

Tag Archives: net

Access password protected URL with Authenticator

With this example we are going to demonstrate how to access a password protected URL using the Authenticator Class. The class Authenticator represents an object that knows how to obtain authentication for a network connection. Usually, it will do this by prompting the user for information. Applications use this class by overriding getPasswordAuthentication() in a sub-class. This method will typically ...

Read More »

Read text from URL

This is an example of how to parse text from a URL. The URL Class is used to represent a Uniform Resource Locator, a pointer to a “resource” on the World Wide Web. Parsing text from a URL implies that you should: Create a URL object from the String representation.  Use openStream() API method to open a connection to this ...

Read More »

Parse URL example

In this example we shall show you how to parse a URL. Class URL represents a Uniform Resource Locator, a pointer to a “resource” on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database ...

Read More »

Convert between URL and URI

With this example we are going to demonstrate how to convert between a URL and a URI. Class URL represents a Uniform Resource Locator, a pointer to a “resource” on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as ...

Read More »

Create Server Socket

This is an example of how to create a ServerSocket. A server socket waits for requests to come in over the network. It performs some operation based on that request, and then possibly returns a result to the requester. Creating a server socket implies that you should: Create a ServerSocket, bound to a specified port. Use accept() API method to ...

Read More »

Write text to Socket

In this example we shall show you how to write text to a Socket. To write text to a Socket one should perform the following steps: Get the output stream of the socket, using getOutputStream() API method of Socket. Create an OutputStreamWriter with the socket ouputstream. Create a BufferedWriter that uses a default-sized output buffer. Use write(String str) API method to ...

Read More »

Read text from Socket

With this example we are going to demonstrate how to read text from a Socket. A Socket is an endpoint for communication between two machines. In short, to read text from a socket you should: Get the socket input stream, using getInputStream() API method of Socket. Create a new BufferedReader, using a new InputStreamReader with the socket input stream. Use readLine() ...

Read More »

Send HTTP POST request with Socket

This is an example of how to send an HTTP POST request with a Socket. A socket is an endpoint for communication between two machines. Sending an HTTP POST request using a Socket implies that you should: Get the InetAddress of a specified host, using the host’s name, with getByName(String host) API method of InetAddress. Create a new Socket and connect ...

Read More »

Create client Socket with timeout

In this example we shall show you how to create a client Socket with timeout. A client socket is an endpoint for communication between two machines. To create a client socket with timeout one should perform the following steps: Get the InetAddress of a specified host, using the host’s name, with getByName(String host) API method of InetAddress. Create a new ...

Read More »

Create client Socket

With this example we are going to demonstrate how to create a client Socket in Java. In short, to create a socket and connect to a remote server you should : Define the Address of the server socket to connect to Define the specific port the server process running on the remote socket listens to Create a new socket and ...

Read More »