Home » core java » Page 30

Tag Archives: core java

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 »

Send network DatagramPacket

This is an example of how to send a Datagram packet over the network in Java. Sending Datagram packets between two hosts in Java implies that you should : Retrieve the Address object of the target host. This object contains all address related information about the specific host Create a DatagramPacket Object providing the actual data to be send, the ...

Read More »

Receive network DatagramPacket

In this example we shall show you how to receive a Datagram packet in Java. For a host to receive Datagram packets in Java implies that you should : Create a DatagramPacket Object providing a placeholder for the received data – here an empty byte array of the default 256 bytes size Create a DatagramSocket Object to receive the Datagram ...

Read More »

Get response headers from HTTP request

With this example we are going to demonstrate how to get response headers from an HTTP request in Java. In short, to get the response headers from an HTTP request you should : Create a URL Object that represents the resource you want to access Use the openConnection() API method of the URL Object to access connection specific parameters for ...

Read More »

Send cookie with HTTP request

This is an example of how to send a cookie with an HTTP request in Java. In short, to send cookies with HTTP requests one should : Create a URL Object that represents the resource you want to access Use the openConnection() API method of the URL Object to access connection specific parameters for the HTTP request Use the setRequestProperty() ...

Read More »