Exp 6
Exp 6
(a) Network Programming With java.net Package, Client and Server Programs, Content
And Protocol Handlers.
(b) write program using java.net Package for client and server program.
(a) The term network programming or networking associates with writing programs that can be
executed over various computer devices, in which all the devices are connected to each other to
share resources using a network.
(b) A socket is one endpoint of a two-way communication link between two programs running on
the network. The socket is bound to a port number so that the TCP layer can identify the
application that data is destined to be sent. In java socket programming example tutorial, we will
learn how to write java socket server and java socket client program. We will also learn how
server client program read and write data on the
socket. java.net.Socket and java.net.ServerSocket are the java classes that implements Socket
and Socket server.
© Java Socket Server Example:
package com.journaldev.socket;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ClassNotFoundException;
import java.net.ServerSocket;
import java.net.Socket;
/**
* This class implements java Socket server
* @author pankaj
*
*/
public class SocketServerExample {
//static ServerSocket variable
private static ServerSocket server;
//socket server port on which it will listen
private static int port = 9876;
package com.journaldev.socket;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
/**
* This class implements java socket client
* @author pankaj
*
*/
public class SocketClientExample {