Home » core java » Page 30

Tag Archives: core java

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 »

Get hostname from IP address

This is an example of how to get the host name of a remote host from its IP address. Doing hostname resolution from IP addresses implies that you should : Retrieve the Address object for the specified host that contains all address related information about the specific host Use the getHostName() and/or getCanonicalHostName() API methods to retrieve the hostname and/or ...

Read More »

Get IP address and hostname from local machine

In this example we shall show you how to retrieve the IP address and hostname from the local host. To get the IP address and hostname from the local machine one should perform the following steps : Retrieve the Address object for the local host. This object contains all address related information about the specific host Use the getAddress() API ...

Read More »

Get IP address from hostname

In this example we shall show you how to retrieve the IP address from the hostname of a specific host. To get the IP address using a hostname one should perform the following steps : Retrieve the Address object of the specific host. This object contains all address related information about the specific host Use the getAddress() API method to ...

Read More »