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 »