140 likes | 548 Views
Sockets. The server waits, listening to the socket for a client to make a connection requestThe client knows the hostname of the machine on which the server is running and the port number to which the server is connectedThe server accepts the connection. The server gets a new socket bound to a dif
E N D
1. CHAT APPLICATION This presentation was based on work of the Mexican students in our laboratory
Sockets
Multicast Chat
Connection of two applications
2. Sockets The server waits, listening to the socket for a client to make a connection request
The client knows the hostname of the machine on which the server is running and the port number to which the server is connected
The server accepts the connection. The server gets a new socket bound to a different port. It needs a new socket (and consequently a different port number) so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client. A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent. A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.
3. On the client side, if the connection is accepted, a socket is successfully created and the client can use the socket to communicate with the server
The client and server can now communicate by writing to or reading from their sockets
4. Steps Open a socket.
Server
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
Client
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
5. Open an input stream and output stream to the socket.
PrintWriter out = new PrintWriter(
clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(
clientSocket.getInputStream()));
Read from and write to the stream .
out.println(text); in.readLine()
Close the streams.
Close the socket.
out.close();
in.close();
clientSocket.close();
serverSocket.close();
6. Network Hosts (chat users) connected to each router
Link state data is obtained from pings
7. Dijkstras Algorithmwith Chat
9. Arrives a new member
10. Apor - Jutas
11. Levedi arrives
12. Between two chat applications Protocol to communicate the two applications