Definition: Network Programming

Computer network programming involves writing computer programs that Allow processes to communicate with each other across a computer network.

 

 

Below is the lists of Some Java.NET Package Classes

Java.NET Package
Classes                                                                        Description
InetAddress This class represents an Internet Protocol (IP) address.
URL Class URL represents a Uniform Resource Locator, a pointer to a “resource” on the World Wide Web.
URLConnection The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL.
ServerSocket This class implements server sockets.
Socket This class implements client sockets (also called just “sockets”).
DatagramPacket This class represents a datagram packet.
DatagramSocket This class represents a socket for sending and receiving datagram packets.

 

 

Socket Basics

A Socket is one end point of two way communication link between two programs running on the network

 

A Socket is combination of an IP Address and a Port Number

 

Socket

 

 

Client – Server Communication

Client-Server request response

  • Two Machines must Connect
  • Server waits for Connection
  • Client initiates Connection
  • Server respond to the client request

 

Socket Overview
The server is just like any ordinary program running on a computer

 

Each Computer is equipped with some ports.

 

The server connects to one of the ports

 

This process is called Binding to a port

 

The Connection is called a server Socket

 

The Java server code that does this is as given below

 

ServerSocket ss = new ServerSocket(2412)

 

Here 2412 is the port number

 

Server waits for the client machine to connect

 

Client possibly running on different machine

 

Client then connect to the connects to the port of the server’s computer

 

Connection is called a Client Socket

 

Socket s = new Socket (‘www.examradar.com’ ,80)

 

Clients already know the port 80

 

Now we can say connection is established between the client and server, Every time a client is found, its socket is extracted, and loop again waits for the next client.