In this tutorial we will learn how to write a simple client server chat program in java. We will right both the server and client side of this program. One of the ways computers can communicate to each other through the internet is by using TCP/IP.
A network socket is an endpoint of an inter-process communication flow across a computer network. Today, most communication between computers is based on the Internet Protocol; therefore most network sockets are Internet sockets.
A socket address is the combination of an IP address and a port number, much like one end of a telephone connection is the combination of a phone number and a particular extension. Based on this address, internet sockets deliver incoming data packets to the appropriate application process or thread.
An Internet socket is characterized by a unique combination of the following:
- Local socket address: Local IP address and port number
- Remote socket address: Only for established TCP sockets. As discussed in the client-server section below, this is necessary since a TCP server may serve several clients concurrently. The server creates one socket for each client, and these sockets share the same local socket address.
- Protocol: A transport protocol (e.g., TCP, UDP, raw IP, or others). TCP port 53 and UDP port 53 are consequently different, distinct sockets.
So, now lets get started with the actual code...
- Client.java:
- Server.java:
Note: If you want to implement the Server & Client on Different PC's then the only change required is changing the InetAddress.getLocalHost() in Client.java to the IP address of the Server PC!!
SNAPSHOTS OF SERVER & CLIENT SIDES
You can Contact Me for further assistance.
0 comments:
Post a Comment