Network Programming TCP UDP SCTP (NPTUS)

Instructional Objectives

After participating in this practicum, students are expected to be able to:

  1. Understanding network protocols such as TCP, UDP and SCTP
  2. Get to know Java's capabilities for network programming

1. Network Protocol

Internet Protocol (IP) is a network layer protocol (OSI Reference Model network layer) or internetwork layer protocol (DARPA Reference Model internetwork layer) used by the TCP/IP protocol to address and route data packets between hosts on a TCP/IP-based computer network.

Transmission Control Protocol (TCP) is a protocol that is in the transport layer (either in the seven layers of the OSI reference model or the DARPA model) that is connection-oriented and reliable.

UDP, short for User Datagram Protocol, is a TCP/IP transport layer protocol that supports unreliable, connectionless communication between hosts on a TCP/IP network.

2. Network Programming with Java

Socket programming is a way to use the socket API (Application Programming Interface) component to create an application. Java has provided the java.net package which contains classes and interfaces that provide low-level (Socket, ServerSocket, DatagramSocket) and high-level (URL, URLConnection) APIs (Application Programming Interfaces).

Socket is an IPC (Inter Process Communication) facility for network applications. How socket works can be described as in figure 1.1 and figure 1.2.


Figure 1.1 Client contacts server


Figure 1.2. Server contacts client

A socket is equipped with an address, which consists of the destination IP address and a port number. IP addresses can use local network (LAN) addresses or internet addresses. So sockets can be used for IPC on LANs or the Internet. The port number is an integer used to distinguish services running on the same server computer. Service users use this port number to contact the server computer with the workstation (client).

By using standard port numbers, communication can occur between several computers remotely to perform various network services, because both the sender and the receiver know where the data should be sent using the port number. For example, all systems use port number 23 for TELNET applications or port 80 for website applications. Therefore, in the system design a new type of service will be created by utilizing sockets, a separate port number can be created for the application.

3. Java Network Package

Some java.net classes that can be used in implementing network programming are:

  • Socket(InetAddress address, int port) : to create a stream socket and connection to a port number on a computer that has an IP address.
  • Socket(String host, int port) : to create a stream socket and also a connection to a specific port on a computer based on its name.
  • Socket(InetAddress address, int port, InetAddress localAddr,int localPort) / Socket(String host, int port, InetAddress localAddr, int localPort) : to create a socket and connect it to the intended port on the IP address specified in the address parameter or host name. In addition, the socket will also be bound to the local address and local port. (This is done if the connection between the client and server requires a specified port number).
  • getInetAddress() : to get the target host name and its IP address
  • getPort() : to get the remote host number
  • getLocalPort() : to get the localhost port number
  • getLocalAddress() : to get the local address where the socket is used
  • getInputStream() : returns an input stream object from the socket
  • getOutputStream() : returns the output stream object to the socket
  • ServerSocket( int port [, int backlog [, InetAddress bindAddress ]] ) : to create a server with a specific port, a limit on the number of queues (backlog), and an IP address bindAddress.
  • DatagramSocket(int port) : to indicate the use of a port number as a "door" to receive connections from clients.
  • DatagramSocket(int port, InetAddress laddr) : to establish a connection with the UDP protocol on a specific local IP address and on a specific port number.
  • DatagramSocket() : to form a connection with the UDP protocol on the local host IP address by randomly determining the port number based on the availability of usable port numbers.
  • DatagramPacket(byte[] buf, int length) : to retrieve information.
  • DatagramPacket(byte[] buf, int length, InetAddress address, int port) : to create a Datagram packet that will send data. This constructor requires information about the byte array to be sent and its length, as well as the destination address and port.

Post a Comment

Previous Next

نموذج الاتصال