20-AL-SocketProgramming

20-AL-SocketProgramming - 1 Writing Network Applications...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Writing Network Applications using the TCP/ I P Protocol Stack: Socket Programming 2 Network Applications Communicating TCP UDP I P LL PL TCP UDP I P LL PL TCP UDP I P LL PL Web Br owser Web Ser ver Ftp Ser ver Ftp Client RTSP Ser ver Real Player Client: initiates contact with server (“speaks first”) • typically requests service from server, e.g., Web Browser Server: provides requested service to client • e.g., Web server sends requested Web page Typical network app has two pieces: client and server Client-Server Paradigm 3 How to program? The socket layer TCP UDP I P LL PL TCP UDP I P LL PL TCP UDP I P LL PL Web Br owser Web Ser ver Ftp Ser ver Ftp Client RTSP Ser ver Real Player Socket Layer Socket Layer Socket Layer • Socket Layer: – Programmer’s API to the I P Protocol stack 4 Socket Creation Family Type Protocol TCP PF_I NET SOCK_STREAM I PPROTO_TCP UDP SOCK_DGRAM I PPROTO_UDP • mySock = socket(family, type, protocol); • TCP/ I P-specific sockets • Socket reference – File (socket) descriptor in UNI X – Socket handle in WinSock 5 Specifying Addresses • str uct sockaddr { unsigned shor t sa_family; /* Addr ess family (e.g., AF_I N ET) */ char sa_data[14]; /* Pr otocol-specific addr ess infor mation */ }; • str uct sockaddr _in { unsigned shor t sin_family; /* I nter net pr otocol (AF_I N ET) */ unsigned shor t sin_por t; /* Por t (16-bits) */ str uct in_addr sin_addr ; /* I nter net addr ess (32-bits) */ char sin_zer o[8]; /* N ot used */ }; str uct in_addr { unsigned long s_addr ; /* I nter net addr ess (32-bits) */ }; Generic IP Specific 6 TCP Client/ Server I nteraction Client 1. Create a TCP socket 2. Establish connection 3. Communicate 4. Close the connection Server 1. Create a TCP socket 2. Assign a port to socket 3. Set socket to listen 4. Repeatedly: a. Accept new connection b. Communicate c. Close the connection Server starts by getting ready to receive client connections… 7 TCP Client/ Server I nteraction Client 1. Create a TCP socket 2. Establish connection 3. Communicate...
View Full Document

{[ snackBarMessage ]}

Page1 / 20

20-AL-SocketProgramming - 1 Writing Network Applications...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online