I-Sockets - A PPENDIX I S O C K E T S A PR O G R A M M E R...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
A A PPENDIX PPENDIX I I S S O C K E T S O C K E T S : : A P A P R O G R A M M E R R O G R A M M E R ' ' S S I I NTRODUCTION NTRODUCTION William Stallings Copyright 2008 C.1 SOCKETS, SOCKET DESCRIPTORS, PORTS, AND CONNECTIONS ...................... 3 C.2 THE CLIENT/SERVER MODEL OF COMMUNICATION .......................................... 4 Running a Sockets Program on a Windows Machine Not Connected to a Network ..... 5 Running a Sockets Program on a Windows Machine Connected to a Network, When Both Server and Client Reside on the Same Machine ................................................... 5 C.3 SOCKETS ELEMENTS ................................................................................................... 5 Socket Creation .............................................................................................................. 5 The Socket Address ....................................................................................................... 6 Bind to a local port ......................................................................................................... 6 Data representation and byte ordering .......................................................................... 7 Connecting a socket ....................................................................................................... 8 The gethostbyname() function call ..................................................................... 10 Listening for an incoming client connection ................................................................ 13 Accepting a connection from a client .......................................................................... 13 Sending and Receiving messages on a socket ............................................................. 15 Closing a socket ........................................................................................................... 16 Report errors ...................................................................................................... 16 Example TCP/IP Client Program (Initiating Connection) ........................................... 18 Example TCP/IP server program (passively awaiting connection) ............................. 19 C.4 STREAM AND DATAGRAM SOCKETS .................................................................... 22 Example UDP Client Program (Initiate Connections) ................................................. 22 Example UDP Server Program (Passively Await Connection) ................................... 24 C.5 RUN-TIME PROGRAM CONTROL .............................................................................. 25 Nonblocking socket calls ............................................................................................. 25 Asynchronous I/O (Signal Driven I/O) ........................................................................ 27 C.6 REMOTE EXECUTION OF A WINDOWS CONSOLE APPLICATION .................. 30 Local code .................................................................................................................... 30 Remote Code ................................................................................................................ 34 Supplement to Operating Systems: Internals and Design Principles, Sixth Edition William Stallings Prentice Hall 2008 ISBN-10: 0-13-600632-9 ISBN-13: 978-0-13-600632-9 http://williamstallings.com/OS/OS6e.html Prepared by Dr. Zornitza Genova Prodanoff of U. of North Florida
Image of page 1

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

View Full Document Right Arrow Icon
I-2 The concept of sockets and sockets programming was developed in the 1980s in the Unix environment as the Berkeley Sockets Interface. In essence, a socket enables communications between a client and server process and may be either connection-oriented or connectionless. A socket can be considered an endpoint in a communication. A client socket in one computer uses an address to call a server socket on another computer. Once the appropriate sockets are engaged, the two computers can exchange data. Typically, computers with server sockets keep a TCP or UDP port open, ready for unscheduled incoming calls. The client typically determines the socket identification of the desired server by finding it in a Domain Name System (DNS) database. Once a connection is made, the server switches the dialogue to a different port number to free up the main port number for additional incoming calls. Internet applications, such as TELNET and remote login (rlogin) make use of sockets, with the details hidden from the user. However, sockets can be constructed from within a program (in a language such as C or Java), enabling the programmer to easily support networking functions and applications. The sockets programming mechanism includes sufficient semantics to permit unrelated processes on different hosts to communicate.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern