Presentation is loading. Please wait.

Presentation is loading. Please wait.

Network Programming Eddie Aronovich mail:

Similar presentations


Presentation on theme: "Network Programming Eddie Aronovich mail:"— Presentation transcript:

1 Network Programming Eddie Aronovich mail: eddiea@mta.ac.il

2 How did it started ?

3 How can we write communication ? 4 Application Program Interface (API) –Sockets –TLI (Transport Layer Interface) 4 System calls 4 Library functions

4 What is it for ? Communication systems provides 3 services: –Information & resource Sharing –Distance gapping –Backup abilities

5 Fundamentals 4 Server - An entity which gives services 4 Client - An entity which requests services 4 Transport layer - To transfer the data

6 The 7 layers model

7 The 7 Layer model in real life

8 The message is built in one side...

9 And striped in the dest. side…

10 From Lynx to Netscape or chat client Presentation

11

12 Descriptors 4 Everything in Unix is a file 4 Descriptor is an index into an array

13 Memory Buffers 4 Contains Socket Address Structure 4 Headers 4 Data

14 The Basics of communication LectureII

15 Processing Techniques

16 The Client  Server Model 4 The server roles: –Give service as asked –Wait the client to appeal to him 4 The client roles: –Start the communication process –Asks the wanted service

17 Design considerations 4 Serve single or multiple users 4 Use reliable or unreliable protocol 4 Software updates

18 Client and server roles in UDP 4 Server roles: –Bind a port –Wait for a message to come –Send reply 4 Client roles: –Send a message –Get the reply

19 User Datagram Protocol* 4 Simple protocol 4 Connectionless 4 Unreliable *{RFC 768}

20 Socket:={ip_addr, port number} 4 API, an interface for the program to contact with communication. 4 Enable usage of regular file commands as read, write and so on. 4 The sockets are structures passed from kernel to process and vice versa.

21 What the socket struct contains ? 4 Socket type {stream, dgram, raw,…} 4 Socket options {broadcast, OOB...} 4 Time to linger wait before close the socket 4 Socket state flags 4 Protocol Control Block 4 Protocol Handle

22 The socket & address structs  General struct sockaddr { uint8_tsa_len; /*Len of socket struct */ sa_family_tsa_family; /*Addr family as AF_INET */ charsa_data[20];/*Protocol Address*/  IP V4 address socket struct sockaddr_in { uint8_t sin_len; /*The socket length */ sa_family_tsin_family;/*AF_INET for IP addresses*/ unit16_t sin_port;/*The port id 16-bit port num */ structin_addr sin_addr;/*The IP address 32-bit */ charsin_zero [8]; /* FFU - Must be zero */

23 How the socket is created 4 The system call passes identifiers for address family(e.g. AF_UNIX, AF_INET,etc.), socket type and protocol. 4 Socket data structure is allocated. 4 Pointer from the fd table to other i-node struct which points to the socket.

24 User Datagram Protocol (rfc 768) 4 Data transport layer protocol (Fragment packets to fit local MTU) 4 Used to make available datagram packet switched mode 4 Connectionless protocol 4 Used when RTT is important or no connection needed

25 UDP header Source port number (16 bit) Destination port number (16 bit) Length (16 bit) UDP Checksum (16 bit) Data

26 UDP by network monitor

27 Lets do it in UDP - client C:\TEMP\udp-cli-c.htm

28 Lets do it in UDP - server C:\TEMP\udp-srv-c.html

29 TCP LectureIII

30 Transmission Control Protocol rfc 793 rfc 793 4 Reliability 4 Sequenced data transfer 4 Flow control 4 Full duplex

31 TCP Header Source port number (16 bit) Dest port number (16 bit) Sequence number (32 bit) Acknowledgement number (32 bit) Header length (4 bit) F.F.U (6 bit) URGACK PSHRST SYN FIN Window size (16 bit) TCP Checksum (16 bit) Urgent Pointer (16 bit) Options Data

32

33

34 Ack & Flow control 4 Acknowledgements are sent by byte. 4 The acks can be sent for group of packets (but should arrive before time out of first packet). 4 Window size is used for flow control and is controlled by receiver.

35 How connection starts ? connect();listen(); connect returns…. accept(); accept returns…. SYN j SYN k, ACK j+1 Connection Established ACK k+1

36 How we do it in C ? ServerClient socket(); bind(); connect(); listen(); accept(); {New file descriptor is given}

37 Ending Sessions Passive close (FIN arrives) Vs. Active close FIN M ACK M+1 FIN N ACK N+1

38 Internet Protocol LectureIV

39 Network Layer 4 Passing packet from source host to destination host (cross networks if needed) 4 Independent of the datalink layer 4 QoS 4 Flow control

40 Internet Protocol 4 Connectionless 4 Unreliable 4 Best effort

41 Address 4 IP address consist 32bit and is divided into {network id.,host id} 4 Part of host id can be used for subnet mask 4 Some special addresses are defined (as: net- addr, broadcast-addr, multicast-addr)

42 Addresses and Classes Class A Addresses: 0-127.X.X.X Class B Addresses: 128-191.0-255.X.X Class C Addresses: 192-223.0-255.0-255.X 01XXXXXX 10XXXXXX 110XXXXX

43 Masks 4 Mask is used to refine network division. 4 ‘1’b in mask symbolize bit belongs to network address. 4 ‘0’b in mask symbolize bit belongs to host address.

44 Address conventions 4 Network address filled with ‘0’ in host address. 4 Broadcast address filled with ‘1’ in host address. 4 First, last subnet and address aren’t used

45 How routing is done ? 4 The router compares destination IP with each Network & subnet address. 4 Unknown destination is routed to default. 4 Routers update each other with appropriate algorithms.

46

47

48

49

50

51 VI שיעור I/O Multiplexing

52 I/O Models 4 Blocking I/O 4 Nonblocking I/O 4 I/O Multiplexing 4 Signal driven 4 Asynchronous I/O

53 Non-Blocking I/O 4 No blocking is done (Error is returned) 4 Reading is done in loop (until data arrives) 4 Polling – costs CPU time 4 Implementation in real time systems only

54 Signal Driven I/O 4 Signal handler should be started

55


Download ppt "Network Programming Eddie Aronovich mail:"

Similar presentations


Ads by Google