#include DatatypeDescription int8_t uint8_t int16_t uint16_t int32_t uint32_t Signed 8-bit integer Unsigned 8-bit integer Signed 16-bit integer Unsigned.

Slides:



Advertisements
Similar presentations
Socket Programming 101 Vivek Ramachandran.
Advertisements

Ipv4 Socket Address Structure struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 address */ /* network byte ordered */ }; struct sockaddr_in { uint8_t sin_len;
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
CSCE 515: Computer Network Programming Socket Wenyuan Xu Department of Computer Science and Engineering.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Tutorial 8 Socket Programming
CS 311 – Lecture 19 Outline Internet Sockets – gethostname utility – struct hostent – inet_addr – Machine byte to Network byte order translation and vice.
Introduction to Socket Programming April What is a socket? An interface between application and network –The application creates a socket –The socket.
Unix Network Programming Part 2: Elementary Sockets Jani Peusaari.
Introduction to Project 1 Web Client and Server Jan 2006.
Lecture 10 Overview. Network API Application Programming Interface – Services that provide the interface between application and protocol software often.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
ECE453 – Introduction to Computer Networks Lecture 15 – Transport Layer (II)
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Operating Systems Chapter 9 Distributed Communication.
Client-Side Network Programming
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Introduction to Socket Programming Advisor: Quincy Wu Speaker: Kuan-Ta Lu Date: Nov. 25, 2010.
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
Sirak Kaewjamnong Computer Network Systems
1 CMPT 471 Networking II Transport Layer Network Programming © Janice Regan, 2013.
Ports Port - A 16-bit number that identifies the application process that receives an incoming message. Reserved ports or well-known ports (0 to 1023)
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Introduction to Socket
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
1 CS716 Advanced Computer Networks By A. Wahid Shaikh.
Socket address structures Byte ordering IP address conversion
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
Sockets Introduction Socket address structures Value-result arguments
Introduction to Sockets
Socket Programming(2/2) 1. Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
回到第一頁 Client/sever model n Client asks (request) – server provides (response) n Typically: single server - multiple clients n The server does not need.
1 Network Programming. 2 Background Important guidelines –Use conductor.tamucc.edu or any LINUX machine to develop your network applications –Do not use.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
CSE 333 – SECTION 8 Client-Side Network Programming.
Name and Address Conversions
Read: Chapters 1,2, 3, 4 Communications Client Server Ex: TCP/IP
Onward with Chat! Networking CS 3470, Section 1.
Advanced Computer Networks
Network Programming CSC- 341
Socket Programming (Cont.)
CS 105 “Tour of the Black Holes of Computing”
Network Programming CSC- 341
Chapter4 Elementary TCP Socket
Network Programming with Sockets
Chapter 3 Sockets Introduction
Network Programming CSC- 341
Advanced Network Programming spring 2007
Lecture 2 Socket Programming
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Today’s topic: Basic TCP API
Presentation transcript:

#include DatatypeDescription int8_t uint8_t int16_t uint16_t int32_t uint32_t Signed 8-bit integer Unsigned 8-bit integer Signed 16-bit integer Unsigned 16-bit integer Signed 32-bit integer Unsigned 32-bit integer sa_family_t socklen_t Address family of socket address structure Length of socket address structure, normally uint32_t in_addr_t in_port_t IPv4 address, normally uint32_t TCP or UDP port, normally uint16_t

Byte Ordering 16-bit integer is made up of 2 bytes. 2 ways to store the bytes in memory Little-endian byte order: low order byte at the beginning address Big-endian byte order: high-order byte at the starting address

Network byte order and host byte order TCP/IP specifies a standard representation for binary integers used in protocol headers called Network byte order that represents integers with the most significant byte first We refer to the byte ordering used by given system as the host byte order

Byte-ordering functions Following function converts integers htons--from host to network byte order short unit16_t htons(unit16_t value); ntohs--from network to host byte order short unit16_t ntohs(unit16_t value); htonl—from host to network byte order long unit32_t htonl(unit32_t value); ntohs--from network to host byte order long unit32_t ntohl(unit32_t value);

bzero function Syntax void bzero( void *dest, size_t nbytes); It is provided by most the system to set nbytes of memory pointed by dest as 0. Example bzero( &servaddr, sizeof(servaddr)); Will set servaddr ( server address struct) as 0

Group of address conversion functions int inet_aton( const char *strptr, struct in_addr *addrptr); Returns; 1 if string was valid, 0 on error convert from ASCII string to network byte order binary values char * inet_ntoa( struct inaddr inaddr); Return: pointer to dotted-decimal string Convert from network byte order binary value to dotted decimal string These two functions convert IPv4 address

int inet_pton( int family, const char* strptr, void *addrptr); Function will convert IP address in string( strptr) to the numeric value as in address struct( addptr). Return 1 if OK, return –1 on error

Const char *inet_ntop(int family, const void *addptr, char *strptr, size_t len); return pointer if K, NULL on error Does the reverse conversion, from numeric (addptr) to presentation (strptr). The len is the size of the destination, to prevent the function from overflowing the caller’s buffer.

Wrapper functions In any real world program it is essential to check every function call for error return. Since terminating on an error is the common case, we can shorten our programs by defining a wrapper function that performs the actual function call, tests, the return value, and terminates on an error s = Socket(AF_INET, SOCK_STREAM, 0);

Wrapper function Socket() int Socket( int family, int type, int protocol) { int n; if( n = socket( family, type, protocol)) < 0) { printf(“socket error\n”); exit(0); } return n; }