Unformatted text preview:

UNIX SocketsProject #1 LogisticsProject #1 OverviewProject #1 DetailsProject #1 Details contd.Slide 6GradingBerkeley SocketsConnection-oriented example (TCP)Connectionless example (UDP)Socket callBind callListen callAccept callConnect callSend(to), Recv(from)Socket ImplimentationPractical issues – using socketsFall, 2001 CS 640 1UNIX SocketsOutlineHomework #1 posted by end of dayProject #1 posted nowUNIX sockets(Applications to continue on Thursday)Fall, 2001 CS 640 2Project #1 Logistics•First of three programming assignments for the class–Due 10/16 at 11:59:59•Late solutions not accepted–Two person teams–Program will be turned in electronically•Directions to be posted–Programs must be written in C or C++–Use the Linux/TUX lab for your work•Everyone in class should have an accountFall, 2001 CS 640 3Project #1 Overview•This assignment requires you to write two programs–blaster (server)•sends data–blastee (client)•receives data–makefile •The goal of this project is to introduce you to UNIX network programming–UNIX tools•Editor, compiler, debugger–SocketsFall, 2001 CS 640 4Project #1 Details•blaster–Sends UDP packets of variable sizes to specified host–Packet format:–Packet types:•‘D’ = DATA•‘E’ = END–Sequence number•Unsigned and in network byte order•Reflects number of payload bytes sent•Can start at an arbitrary value–Data payload can be anything8 bit Packet Type32 bit Sequence Variable Length PayloadFall, 2001 CS 640 5Project #1 Details contd.•blaster accepts the following command line parameters–Host and port of blastee–Rate at which packets are sent (packets/second)–Total number of packets which will be sent and/or duration of test (in seconds)–Initial sequence number–Size of payload portion of packets•A test consists of blaster sending packets to blasteeFall, 2001 CS 640 6Project #1 Details contd.•blastee must allow user to specify listen port•For each DATA packet received, print to screen and/or file a text line with:–Blaster’s IP (dot notation) and port number–Packet size (bytes)–Packet sequence number–Time (milliseconds) packet was received•After END packet received print to screen and/or file a text line with summary info:–Total packets received–Total bytes received–Average packets/sec and bytes/sec–Duration of test (seconds)Fall, 2001 CS 640 7Grading•Grades given by demo only–20 points: code compiling cleanly–30 points: send any data and print that data is received–10 points: blastee decodes packets and prints details–10 points: number of packets/duration of test–10 points: rate of test test and payload size–10 points: sequence numbers–10 points: generate/send END and prints summaryFall, 2001 CS 640 8Berkeley Sockets•Networking protocols are implemented as part of the OS–The networking API exported by most OS’s is the socket interface–Originally provided by BSD 4.1c ~1982.•The principal abstraction is a socket–Point at which an application attaches to the network–Defines operations for creating connections, attaching to network, sending/receiving data, closing.Fall, 2001 CS 640 9Connection-oriented example (TCP)ServerSocket()Bind()ClientSocket()Listen()Accept()Recv()Send()Connect()Send()Recv()Block untilconnectProcessrequestConnection Establishmt.Data (request)Data (reply)Fall, 2001 CS 640 10Connectionless example (UDP)ServerSocket()Bind()ClientSocket()Recvfrom()Sendto()Bind()Sendto()Recvfrom()Block untilData from clientProcessrequestData (request)Data (reply)Fall, 2001 CS 640 11Socket call•Means by which an application attached to the network•int socket(int family, int type, int protocol)•Family: address family (protocol family)–AF_UNIX, AF_INET, AF_NS, AF_IMPLINK•Type: semantics of communication–SOCK_STREAM, SOCK_DGRAM, SOCK_RAW–Not all combinations of family and type are valid•Protocol: Usually set to 0 but can be set to specific value.–Family and type usually imply the protocol •Return value is a handle for new socketFall, 2001 CS 640 12Bind call•Binds a newly created socket to the specified address•Int bind(int socket, struct sockaddr *address, int addr_len)•Socket: newly created socket handle•Address: data structure of address of local system–IP address and port number (demux keys)–Same operation for both connection-oriented and connectionless servers•Can use well known port or unique portFall, 2001 CS 640 13Listen call•Used by connection-oriented servers to indicate an application is willing to receive connections•Int(int socket, int backlog)•Socket: handle of newly creates socket•Backlog: number of connection requests that can be queued by the system while waiting for server to execute accept call.Fall, 2001 CS 640 14Accept call•After executing listen, the accept call carries out a passive open (server prepared to accept connects).•Int accept(int socket, struct sockaddr *address, int addr_len)•It blocks until a remote client carries out a connection request.•When it does return, it returns with a new socket that corresponds with new connection and the address contains the clients addressFall, 2001 CS 640 15Connect call•Client executes an active open of a connection•Int connect(int socket, struct sockaddr *address, int addr_len)•Call does not return until the three-way handshake (TCP) is complete•Address field contains remote system’s address•Client OS usually selects random, unused portFall, 2001 CS 640 16Send(to), Recv(from)•After connection has been made, application uses send/recv to data•Int send(int socket, char *message, int msg_len, int flags)–Send specified message using specified socket•Int recv(int scoket, char *buffer, int buf_len, int flags)–Receive message from specified socket into specified bufferFall, 2001 CS 640 17Socket Implimentation•Protocol implementation–Process per protocol•Use a separate process to implement each protocol•Messages are passes between processes–Process per message•Use one process to handle each message/communication•Generally more efficient•Buffer use–Applications use buffers as do protocols•Copies are VERY expensive•Message abstraction enables pointers to be used and minimal copiesFall, 2001 CS 640 18Practical issues – using sockets•You have to be very careful when using these calls–Specific data structures and formats–Ports cannot be less than 1024•You can use other tools


View Full Document

UW-Madison CS 640 - UNIX Sockets

Documents in this Course
Security

Security

21 pages

Mobile IP

Mobile IP

16 pages

Lecture 7

Lecture 7

36 pages

Multicast

Multicast

38 pages

Load more
Download UNIX Sockets
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view UNIX Sockets and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view UNIX Sockets 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?