Java Socket Programming (Client Server Program)
Java Socket Programming (Client Server Program)
x
Java Socket Programming (Client Server
Program)
Categories
In this tutorial I have shared simple client server program example to explain java socket Algorithm
programming. Array
Articles
In this example I will use Socket and ServerSocket classes for connection oriented
Basic
socket programming. Since data is shared between server and client over network in the
Books
form of streams so DataInputStream and DataOutputStream classes are used. Collection
Data Structure
Subscribe To Get Free Java Programming Tutorials Directly In Your Inbox! Design Pattern ×
Java Socket Programming (Client Server Eclipse
Above code is used to create server which is running on localhost on port number 5000.
Client
Subscribe To Get Free Java Programming Tutorials Directly In Your Inbox!
import java.io.DataOutputStream;
×
import java.net.Socket;
import java.util.Scanner;
Enter your email address:
class client {
public static void main(String args[]){
String message;
Scanner sc = new Scanner(System.in);
try{ Subscribe
//localhost because server is running on local machine, otherwise use ip o
Socket socket = new Socket("localhost", 5000);
Since the server is running on local machine so I have used locahost while creating
connection. Otherwise use the IP address of server.
How to Execute?
1. First open a command prompt and run server program. The server will wait for client
to be connected.
Subscribe
2. Now open another command prompt and run client program. This will connect client x
x
with server. Enter a message at client side to send it to server.
Enter
Comment below if you have any queries regarding above yourserver
client email program
address:in java.