Computer Networking From LANs to WANs: Hardware, Software, and Security Chapter 16 Writing a Network Application
Computer Networking From LANs to WANs: Hardware, Software, and Security2 Objectives Discuss the client-server model Explain the basic features of a socket Summarize the various network programming languages Show examples of both connectionless and connection-oriented network applications
Computer Networking From LANs to WANs: Hardware, Software, and Security3 Client-Server Model Client –Sends message to request server service –Message encapsulated inside a network packet Transmitted over physical connection Server –Responds to client using a message Contains client's desired information Takes other appropriate action Client-server messages –Text based or data
Computer Networking From LANs to WANs: Hardware, Software, and Security4 Client-Server Model (cont’d.) Figure 16-1 Client-server network model
Connection-Oriented Versus Connectionless Communication Connection-oriented communication –Requires an established client-server session Connectionless communication –Client and server hope messages arrive correctly Application not severely affected if delivery is lost or corrupted –Eliminates session overhead Important when speed is an application consideration –Eliminates overkill of setting up a session Useful for small number of exchanged messages Computer Networking From LANs to WANs: Hardware, Software, and Security5
6 Connection-Oriented Versus Connectionless Communication (cont’d.) Table 16-1 Communication types
Computer Networking From LANs to WANs: Hardware, Software, and Security7 Sockets Input/output mechanism for network messages –Used by every network application to communicate Windows Sockets Application Programming Interface (Winsock API) –Initialization performed automatically –Uses single WSAStartup function call
Computer Networking From LANs to WANs: Hardware, Software, and Security8 Sockets (cont’d.) Winsock API (cont’d.) –Create Windows environment TCP socket type Use IPPROTO_TCP –Create Windows environment UDP socket Use the socket() function
Computer Networking From LANs to WANs: Hardware, Software, and Security9 Sockets (cont’d.) Blocking mode (default) –Program stops and waits for a received packet Nonblocking mode –Program does not stop and wait for new packet arrival Change socket mode
Computer Networking From LANs to WANs: Hardware, Software, and Security10 Sockets (cont’d.) Client sockets and server sockets require slightly different initialization Client initialization code
Computer Networking From LANs to WANs: Hardware, Software, and Security11 Sockets (cont’d.) Server initialization code –Server must bind address information to the socket IP address and socket port number used to uniquely identify socket –If another application already using the same port bind() function will discover it
Sockets (cont’d.) Session oriented (TCP) socket communication –Server calls the listen() function, waits for connection –Client calls the connect() function, initiates a session Acknowledged by server function accept() –Functions send() and recv() used by both the client and server to exchange messages Connectionless (UDP) communication –After address structure initialization Client and server simply exchange messages using the sendto() and recvfrom() functions Close socket with closesocket(), WSACleanup() Computer Networking From LANs to WANs: Hardware, Software, and Security12
Computer Networking From LANs to WANs: Hardware, Software, and Security13 Figure 16-3 Client Server Connectionless (UDP) communication
Computer Networking From LANs to WANs: Hardware, Software, and Security14 Sockets (cont’d.) Table 16-2 Winsock functions
Computer Networking From LANs to WANs: Hardware, Software, and Security15 Network Programming Languages C/C++ –Supports connectionless, connection-oriented communications –Anyone with a C/C++ compiler and networking library can develop network applications C# –Eliminates C++ program complexity –Provides C++ programming flexibility –Provides Visual Basic visual features
Computer Networking From LANs to WANs: Hardware, Software, and Security16 Network Programming Languages (cont’d.) Visual Basic –Compiled executable programs and scripts –IIS Applications Server applications Compiled application receives and processes service requests from a Web browser –DHTML Applications Client applications Interface directly with the browser
Network Programming Languages (cont’d.) Practical Extraction and Reporting Language (Perl) –Interpreted language useful for CGI applications –Perl programs are called scripts Not precompiled; stored in binary form Processed upon demand Easily ported to other computing environments Host machine must provide a Perl interpreter –Works with text and binary files –Equipped with standard programming elements Conditional statements, arithmetic and logical operations, loops, and subroutines Computer Networking From LANs to WANs: Hardware, Software, and Security17
Computer Networking From LANs to WANs: Hardware, Software, and Security18 Network Programming Languages (cont’d.) Java –Uses applets Transferred from server to browser client Executed on a Java virtual machine contained within the browser –Supports stream (TCP) and datagram (UDP) sockets Through java.net package –Remote method invocation (RMI) Provides additional networking capabilities Allows distributed Java objects to communicate with each other
Computer Networking From LANs to WANs: Hardware, Software, and Security19 Network Applications All available on companion CD –Sample executions –Messages passed between the client and server in each case Echo server –Connectionless application Returns same message back to the client –ECHOSRVR Must be started first with user-supplied port number –ECHOCLNT Displays greeting, asks for message to send
Computer Networking From LANs to WANs: Hardware, Software, and Security20 Network Applications (cont’d.) Time server –Connectionless application Replies to a client message with current time and date message –TIMESRVR: server application Must be started with user-supplied port number –TIMECLNT: time client Must be started with server address and the same port number
Computer Networking From LANs to WANs: Hardware, Software, and Security21 Network Applications (cont’d.) Tic-Tac-Toe –UDP datagrams exchange game information –Server responsibilities: Checking legality of client’s move Making its own countermove Testing for win, lose, tie after each move
Computer Networking From LANs to WANs: Hardware, Software, and Security22 Network Applications (cont’d.) Chat server –Chat Server and Chat Client programs Implements client-server architecture –Chat Client Sends message to the server Displays any message from the server –Chat Server Waits for client message Sends any received message to all clients –Chat Server must be running: Before Chat Client can connect
Computer Networking From LANs to WANs: Hardware, Software, and Security23 Network Applications (cont’d.) NETMAZE –Most complex of all client-server examples –Contains both client code and server code Uses command line parameters to enter one mode or the other –Should be run on newer computer system DirectX package must be installed –Goal Walk around the maze and find the exit
Computer Networking From LANs to WANs: Hardware, Software, and Security24 Network Applications (cont’d.) CGI IP Address Calculator –IPCLASS version Uses data POSTed from the FORM element to generate text-only output back to the browser –IPCLASS2 version Returns HTML output Allows WYSIWYG formatting
Network Appliances IRP device –Operates using UDP –Special features: Scenix SX52BD micro-controller RealTek RTL8019AS full-duplex Ethernet controller ARP, IP, ICMP, UDP, and DHCP protocol support Two activity indicator LEDs 24 pins of programmable input/output Various input options (TTL, CMOS levels, Schmitt- Trigger inputs or internal pull-up resistors) Utility program for configuring the module and for manually reading and writing to the ports Computer Networking From LANs to WANs: Hardware, Software, and Security25
Computer Networking From LANs to WANs: Hardware, Software, and Security26 Network Appliances (cont’d.) IPS device –Operates using TCP –Special features: Scenix SX52BD micro-controller RealTek RTL8019AS full-duplex Ethernet controller Web server 512 KB of flash memory 16 digital inputs 16 digital outputs 32 digital I/O channels all TTL compatible
Computer Networking From LANs to WANs: Hardware, Software, and Security27 Network Appliances (cont’d.) LS100 –Operates using TCP –Special features: Connect serial devices to an Ethernet network Support for RS232 serial devices using a DB9 connector Serial transfer rate up to 115Kbps Configuration via telnet or serial port Support for ARP, IP/ICMP, TCP/IP, Telnet, DHCP client, and PPPoE protocols
Computer Networking From LANs to WANs: Hardware, Software, and Security28 Figure Network Programming Environment Network Appliances (cont’d.) Interfacing –On-line lab environment Programmer on the Internet can connect to a device and operate it remotely Several students can work at the same time
Troubleshooting Techniques Never make assumptions –Test connections to make sure machines communicate If there is too much delay in client-server connection –Examine path between client and server Verify TCP/IP protocol installed properly and bound to network adapter Verify problem is not operating system-related Check for correct Winsock version number, IP address, and port number Computer Networking From LANs to WANs: Hardware, Software, and Security29
Summary Client server model communication –Client request service –Server responds with information or other action Connection-oriented communication –Requires established client and server session Connectionless communication –Eliminates session overhead Socket: input/output mechanism for network messages Many popular programming languages support networking Computer Networking From LANs to WANs: Hardware, Software, and Security30