0% found this document useful (0 votes)
4 views19 pages

CENG325 10 Networking

The document provides an overview of Java networking, focusing on TCP socket programming, client/server computing, and the essential components such as IP addresses, DNS, transport protocols, and sockets. It explains how a client communicates with a server using sockets, including the creation of server and client sockets in Java, and illustrates data transmission through a client/server example involving the calculation of a circle's area. The document also highlights the importance of the Java API in facilitating network communication.

Uploaded by

42330003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views19 pages

CENG325 10 Networking

The document provides an overview of Java networking, focusing on TCP socket programming, client/server computing, and the essential components such as IP addresses, DNS, transport protocols, and sockets. It explains how a client communicates with a server using sockets, including the creation of server and client sockets in Java, and illustrates data transmission through a client/server example involving the calculation of a circle's area. The document also highlights the importance of the Java API in facilitating network communication.

Uploaded by

42330003
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Java Networking

TCP Socket programming


Content
1. Introduction
 IP address
 DNS
 Transport protocols
 sockets
2. Client/Server Computing
Introduction
 Computer networking is used to send and receive messages
among computers on the Internet.
 To browse the Web or send an email, your computer must be
connected to the Internet.
 The Internet is the global network of millions of computers. Your
computer can connect to the Internet through an Internet Service
Provider (ISP) using a dialup, DSL, or cable modem.
IP address
 When a computer needs to communicate with another
computer, it needs to know the other computer’s address.
 An Internet Protocol (IP) address uniquely identifies the
computer on the Internet. An IP address consists of four
dotted decimal numbers between 0 and 255, such as
130.254.204.31

 A program can use the host name localhost or the IP


address 127.0.0.1 to refer to the machine on which a client
is running.
DNS
 Since it is not easy to remember so many numbers, they are
often mapped to meaningful names called domain names,
such as www.liu.edu.lb, www.facebook.com , etc

 Special servers called Domain Name Servers (DNS) on the


Internet translate host names into IP addresses

 When a computer contacts


www.liu.edu.lb, it first asks the
DNS to translate this domain
name into a numeric IP address
and then sends the request using
the IP address.
Transport protocols
 The Internet Protocol is a low-level protocol for
delivering data from one computer to another across
the Internet in packets.

 Two higher-level protocols used in conjunction with


the IP are the Transmission Control Protocol (TCP) and
the User Datagram Protocol (UDP).
Our
focu
s  TCP can detect lost transmissions and resubmit them,
transmissions are lossless, in order and reliable.

 UDP, in contrast, cannot guarantee lossless


transmission.
Sockets
 A network socket is a software structure within
a network node that serves as an endpoint for
sending and receiving data across the network
(on server and client)
 It is identified by an IP (to identify the host) and a
port number (to identify the process)
 Port numbers range from 0 to 65536 (2 16 ) but
port numbers 0 to 1024 are reserved for
privileged services.
 E.g. web port 80
email port 25
Client/Server communication
 Network programming usually involves one server
and one or more clients.
 The client sends requests to the server, and the
server responds.
 The client begins by attempting to establish a
connection to the server.
 The server can accept or deny the connection.
 Once a connection is established, the client and the
server communicate through sockets.
 The server must be running when a client attempts
to connect to the server.
 The server waits for a connection request from the
client.
Client/Server Computing
 Java API provides the classes for creating sockets to
facilitate program communications over the Internet.
 Java provides the ServerSocket class for creating a server
socket and the Socket class for creating a client socket.
 Programs can read from or write to sockets as easily as they
can read from or write to files.
Client/Server Computing
 Create a server socket:
ServerSocket serverSocket = new ServerSocket(port);

 The server can now listen for connections:


Socket socket = serverSocket.accept();

 This means the server waits until a client connect to the server
socket.

 Then, client issues the following statement to request a connection


to a server using its name or IP:
Socket socket = new Socket("130.254.204.33", 8000);
Socket socket = new Socket("liang.armstrong.edu", 8000);

 When you create a socket with a host name, the JVM asks the DNS to
translate the host name into the IP address.
Data Transmission through Sockets
 After the server accepts the connection,
communication between the server and the
client is conducted in the same way as for I/O
streams.
 To get an input stream and an output stream,
use the getInputStream() and
getOutputStream() methods on a socket
object.
InputStream input =
socket.getInputStream();
OutputStream output =
socket.getOutputStream();

 The server can use input.readDouble() to


receive a double value from the client and
output.writeDouble(d) to send the double
value d to the client.
A Client/Server Example
 This example presents a client program and a
server program.
 The client sends data to a server.
 The server receives the data, uses it to
produce a result, and then sends the result
back to the client.
 In this example, the data sent from the client
comprise the radius of a circle, and the result
produced by the server is the area of the
circle.
Server program
Client program
A Client/Server Example
 Client sends the radius through a
DataOutputStream on the output stream
socket.
 Server receives the radius through the
DataInputStream on the input stream socket
 The server computes the area and sends it to
the client through a DataOutputStream on the
output stream socket, and the client receives
the area through a DataInputStream on the
input stream socket
A Client/Server Example
With GUI - Server
With GU-Client

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy