0% found this document useful (0 votes)
77 views13 pages

Lab 2

This document provides an overview of computer network concepts for a socket programming lab. It discusses protocols, the 5 steps for client/server connection establishment (bind, socket, listen, connect, accept), and defines key terms like protocol, domain, socket type, and the socket creation process for both servers and clients. It explains that protocols define communication rules between devices, and sockets need to specify a protocol. It also outlines the typical workflow for creating server and client sockets in C.

Uploaded by

Vũ Phước
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)
77 views13 pages

Lab 2

This document provides an overview of computer network concepts for a socket programming lab. It discusses protocols, the 5 steps for client/server connection establishment (bind, socket, listen, connect, accept), and defines key terms like protocol, domain, socket type, and the socket creation process for both servers and clients. It explains that protocols define communication rules between devices, and sockets need to specify a protocol. It also outlines the typical workflow for creating server and client sockets in C.

Uploaded by

Vũ Phước
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/ 13

CSE4202 -001

Inha University

Computer Networks - Lab


Socket Programming in C

2. Protocols, socket creation, data transmission


Review (Lab-1):
5-Step Client/Server Connection Establishment

1. Bind
2. Socket
3. Listen
4. Connect
5. Accept

?
1. Socket
Protocol
Protocol

• What is “Protocol”?
• Network protocols are formal standards and policies comprised of rules, procedures and
formats that define communication between two or more devices over a network.
• It needs to be specified to create a socket (so socket needs to know the protocol type)
• It’s like a detailed deal between two people for co-working (or just communicating)
• The both parties can communicate with each other using the agreed terms and conditions
Domain, Type, Protocol

• Socket domain
• PF_XXX  Protocol Family XXX
• PF_INET = Protocol Family Internet (IPv4)

• PF_INET6 = Protocol Family Internet (IPv6)

• AF_XXX  Address Family XXX (each address family supports multiple protocol families)
• AF_INET = Address Family Internet (IPv4)

• AF_INET6 = Address Family Internet (IPv6)


Domain, Type, Protocol

• Socket type
• SOCK_STREAM  TCP (Transmission Control Protocol – Two-way handshaking)
• Connection oriented = stable

• SOCK_DGRAM  UDP (User Datagram Protocol – Doesn’t shake any hands)


• Connectionless = fast

• SOCK_RAW (not needed)


• SOCK_RDM (not needed)
• SOCK_SEQPACKET (not needed)

SOCK_STREAM SOCK_DGRAM

? ?
Domain, Type, Protocol

• Socket protocol (sub-protocol of the selected socket type)


• Could be an icmp, snmp, igp message  as there are various sub protocols available
for machine controlling, information fetching, and so on…
Socket Creation

• Specify the three elements: Domain, Type, Protocol


Now lets create our own socket

• “Server” Socket workflow: Socket()

Bind()

Listen()

Accept()
Now lets create our own socket

• “client” Socket workflow: Socket()

connect()

recv()
Data transmission

Server sends the data

Client reads the data


Compile & Run
the files from blackboard

* gcc –o server tcp_server.c


* gcc –o client tcp_client.c

You might also like