New version page

Networking with Stream-based Sockets

Upgrade to remove ads

This preview shows page 1-2-3-4 out of 11 pages.

Save
View Full Document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Upgrade to remove ads
Unformatted text preview:

The Internet: Networking with Stream-based SocketsThe Internet• A Global Network of Networks• ARPANet: SRI, Utah, UCLA, UCSB, (1969)– Defense Dept. Advanced Research Projects Agency (DARPA)– Stanford Research Institute (Doug Engelbart)– Designed to survive bomb attacks– Distributed control, Expandable• Ethernet– Global standard for interconnecting computers– Xerox PARC (Early 70s)– Client/Server architecture• Exponential Growth– Tens of Millions of Computers– Hundreds of millions of UsersThe Internet• A Packet Switched Network– Like Postal System– Messages broken up into packets (like envelopes)----------------------------------------------------| Error Detect | Data | Header || (Check Sum) | | (Addresses) |---------------------------------------------------Computer Node Addresses:• IP (Internet Protocol)– 32 bit numeric address in four 8-bit fields:– 128.226.6.4 (bingsuns IP Address)| |network computer(city/state) (street/number) <-- postal analogy– Called the IP Address• TCP (Transmission Control Protocol):• Send Site: Breaks message into packets• Receive Site: Collects & Reassembles packets in proper order“Best” path between computers is chosen using Routers2 413756Domain Names• Synonyms for IP Addresses• bingsuns.binghamton.edu| |individual largestmachine domain– Synonym for 128.226.6.4• Internet Domain Name Server (DNS) software maps domain names to IP addressesCommon High-Level Domain Names• com: commercial• edu: educational• gov: government• mil: military• org: other organization• net: network resources• --: country name– e.g., ca = CanadaThe .NET Dns Class• In System.Net namespace• Dns: a class that has methods that retrieve information about aspecific host from the Domain Name Server– Dns.GetHostByName(string hostName)and Dns.GetHostByAddress(string hostIPaddress)static methods– Both return an IPHostEntryobject containing host information • For GetHostByName(hostName)it gives access to the IP address(es) corresponding to the DNS name specified in hostName– That object’s AddressListproperty can be used to set up an array of IPaddresses that correspond to the hostname• For GetHostByAddress(hostIPaddr) it gives access to domain name/aliases for the specified IP address– That object’s Aliases property is an array of domain names– See GetIPAddress example programNetworking Software• Client/Server Model– Client Program -- seeks a service from remote computer– Server Program -- provides a service to a client running on a remote computer– Computers are usually connected over a network– Examples• Print Server• File Server• Information ServerClient/Server ModelInformation Servers• Program handles requests for information• Some examples– e-mail: electronic mail service– telnet/Rlogin/SSH: remote logon services– ftp/SSH: file transfer service– Some older text-based information servers:• gopher: net browsing service (text based)• archie/veronica: automated net search services• WAIS: automated file content search service• Net News: network bulletin board service– WWW: hypermedia access to internet (Web page service)Network Communication Between Computers•Applications running on different computers can communicate with each other–Server Application: Waits for other applications on other computers to open a communication connection –Client Application: Attempts to open a connection •When connection is established, data can be exchanged •Either can close the communication•Connections:–Two programs running on different computers that are communicating with each other form a connection–Data is sent and received along the connectionNetwork Socket Stream• Basic object used to perform network communication• Used to read/write messages going between apps– (Like a file stream in file I/O) • A Socket is a communication "endpoint“– There's a socket at each end of the connection• Windows support for sockets: in the Winsock API – MFC encapsulates this in the CAsyncSocket base class• Provides complete, event-driven socket communications• Lowest level support -- Notes at: www.cs.binghamton.edu/~reckert/360/17b_sockets_f03.html • Higher level support from derived classes like CSocket• .NET encapsulates socket support in:– System.Net.Sockets namespace– With .NET sockets, networking is viewed like file I/O• Read from /write to a socket stream as easily as from/to a file streamMaking a Socket Connection to a Process Running on Another Computer– Specify the IP Address of computer where the other application is running• Identifies a machine– Also specify the Port the application is listening on• Identifies the program that should handle the communication– e.g. port 80 is reserved for web document transfer–IP Address/Port are like number/extension in telephone communication• Port can be any number from 0 to 65535– Numbers 0 to 1023 may be used by the operating system– So use numbers greater than 1023Details of Establishing a Simple Server(Using TCP/IP Network Socket Streams)1. Create a TcpListener class object• TcpListener myListener = new TcpListener(5000);– Parameter: port # to bind the Server to on the machine it’s running on2. Call TcpListener object’s Start( ) method to start listening for connection requests• myListener.Start( );3. Use TcpListener’s AcceptSocket( ) to accept an incoming request and establish the connection• Socket myConnection = myListener.AcceptSocket( );– Returns a Socket object» Socket object will be null if connection was not made» Its Connected property will be true after socket is connected4. Create a NetworkStream associated with the socket• NetworkStream myNetStream = new NetworkStream(myConnection);– This will be used to do the reading and writing as in File I/OUsing the ServerNetwork Stream Connection5. Create BinaryReader and BinaryWriter objects for transferring data across the network streamBinaryWriter myWriter = new BinaryWriter(myNetStream);BinaryReader myReader = new BinaryReader(myNetStream);6. Use BinaryReader/BinaryWriter methods to read/write data, e.g.:string receiveStr, sendStr;receiveStr = myReader.ReadString( );– Reads a line of text from the network stream (sent by the


Download Networking with Stream-based 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 Networking with Stream-based 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 Networking with Stream-based 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?