
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The use of Java sockets and socket programming with TCP in data communication and networks. The document covers topics such as internet transport-layer protocols, multiplexing/demultiplexing, and connection-oriented demux. It also explains how demultiplexing works and provides examples of socket programming with TCP. likely to be useful as study notes or lecture notes for university courses related to computer science, networking, or data communication. It could be associated with the typology of lecture notes and is most likely to belong to a course on computer networks or data communication. The document could be useful for both university and high school students as well as lifelong learners. The document succeeded in providing meaningful information about the title, description, related university topics, correlated university topics, rate, typology, academic course, academic year, user type, and succeeded fields.
Typology: Lecture notes
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























Dr. Jean-Claude Franchitti
Internet Transport-Layer Protocols
Multiplexing / Demultiplexing
Socket Programming
application transport data link^ network physical
application transport data link^ network physical
data link^ network physical
data link^ network physical
data link^ network physical
data link^ network data linknetwork physical physical
source port # dest port #
32 bits
application data (message)
other header fields
TCP/UDP segment format
DatagramSocket mySocket1 = new DatagramSocket(99111) ; DatagramSocket mySocket2 = new DatagramSocket(99222) ;
Client IP:B
P
client IP: A
P4 P2^ P
server IP: C
SP: 9157 DP: 80
SP: 9157 DP: 80
P5 P6^ P
D-IP:C
S-IP: A D-IP:C
S-IP: B
SP: 5775 DP: 80
D-IP:C
S-IP: B
13
Socket API
Goal: learn how to build client/server application that communicate using sockets
a host-local, application-created, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another application process
socket
process
TCP with buffers, variables
socket
controlled by application developer controlled by operating system
host or server
process
TCP with buffers, variables
socket
controlled by application developer controlled by operating system
host or server
internet
Socket Programming With TCP
client reads line from standard input ( inFromUser stream) , sends to server via socket ( outToServer stream)
server reads line from socket
server converts line to uppercase, sends back to client
client reads, prints modified line from socket ( inFromServer stream)
outToServer
to network from network
inFromServer
inFromUser
keyboard monitor
Process
clientSocket
streaminput
streaminput
streamoutput
socketTCP
Client process
client TCP socket
import java.io.; import java.net.; class TCPClient {
public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence;
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
Create input stream Create client socket, connect to server Create output stream attached to socket
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close(); } }
Create input stream attached to socket
Send line to server Read line from server