











































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
During the first semester of our degree program, we study Computer Networks Fundamentals. These lecture slides are very informative for me. The major points which are core of course are:Socket Programming, Roadmap, Application Level, Human Readable, Protocol Layering, Telnet, Directly, Traced, Application Level Protocols, Server Code
Typology: Slides
1 / 51
This page cannot be seen from the preview
Don't miss anything!












































2: Application Layer 1
2: Application Layer 2
Lots more but can’t stay at app level all semester
2: Application LayerDocsity.com 4
2: Application Layer 5
2: Application Layer 7
2: Application Layer 8
2: Application Layer 10
2: Application Layer 11
OVERVIEW: TCP vs UDP
TCP service:
connection-oriented: setup
reliable transport between
flow control: sender won’t
congestion control: throttle
does not provide: timing or
UDP service:
2: Application Layer 13
2: Application Layer 14
Example: Java server (TCP)
import java.io.; import java.net.;
class TCPServer {
public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence;
ServerSocket doorbellSocket = new ServerSocket(6789);
while(true) {
Socket connectSocket = doorbellSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectSocket.getInputStream()));
Create welcoming socket at port 6789
Wait, on welcoming socket for contact by client
Create input stream, attached to socket
2: Application Layer 16
Example: Java client (TCP)
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 connectSocket = new Socket("hostname", 6789);
DataOutputStream outToServer = new DataOutputStream(connectSocket.getOutputStream());
Create input stream
Create client socket, connect to server Create output stream attached to socket
2: Application Layer 17
Example: Java client (TCP), cont.
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(connectSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence );
connectSocket.close();
Create input stream attached to socket
Send line to server
Read line from server
2: Application Layer 19
Example: C server (TCP)
#include <sys/socket.h> #include <netinet/in.h>
Int main(int argc, char **argv) { int doorbellSocket, connectSocket; char clientSentence[MAX_LINE];; struct sockaddr_in servaddr;
doorbellSocket = socket(AF_INET, SOCK_STREAM, 0);
servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(6789);
bind(doorbellSocket, (struct sockaddr *) &servaddr,
sizeof(servaddr)); listen(doorbellSocket , LISTENQ);
Create welcoming socket at port 6789
Warning: Should check return codes of major functions!! Omitted for space here
2: Application Layer 20
Example: C server (TCP), cont
for ( ; ; ) {
connectSocket = accept(doorbellSocket , (struct sockaddr *) NULL, NULL);
bytesRead = read(connectSocket, clientSentence, MAXLINE);
//would have to write the capitalize procedure capitalize(clientSentence);
write(connectSocket, clientSentence, MAXLINE);
close(connectSocket); } close(doorbellSocket); }
Read in line from socket
Write out line to socket
End of while loop, loop back and wait for another client connection
Wait, on welcoming socket for contact by client