1 / 7

Networking

Networking. OSI (Open Systems Interconnection) model of computer networking, seven layers ( the Application, Presentation, Session, Transport, Network, Data Link, and Physical Layers) Internet Protocol Stack, five layers ( the Application, Transport, Network, Data Link, and Physical Layers).

pedror
Télécharger la présentation

Networking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Networking • OSI (Open Systems Interconnection) model of computer networking, seven layers (the Application, Presentation, Session, Transport, Network, Data Link, and Physical Layers) • Internet Protocol Stack, five layers (the Application, Transport, Network, Data Link, and Physical Layers) application application socket controlled by app developer process process transport transport controlled by OS network network link Internet link physical physical

  2. Networking • TCP/IP (Transmission Control Protocol/Internet Protocol) • reliable, byte stream-oriented (reliable transfer of bytesfrom one process to another) • UDP/IP (User Datagram Protocol) • unreliable datagram • Connection model: connection-oriented and connectionless communication Socket : a host-local, application-created, OS-controlled interface into which, application process can both send and receive messages to/from another application process

  3. client must contact server server process must first be running server must have created socket that welcomes client’s contact client contacts server by: Creating TCP socket, specifying IP address, port number of server process when client creates socket: client TCP establishes connection to server TCP when contacted by client, server TCP creates new socket for server process to communicate with that particular client allows server to talk with multiple clients source port numbers used to distinguish clients application viewpoint: Socket programming with TCP TCP provides reliable, in-order byte-stream transfer (“pipe”) between client and server

  4. TCP Socket Communications Client Server Listener Socket (Thread) Client Socket (Thread) Connect Accept Communicate Server Socket 1 (Thread) Server Socket 2 (Thread) Server Socket i (Thread)

  5. TCP Sockets in C++/CLI Client Server • TcpListener ^listener = gcnew TcpListener(IPAddress::Any, 12345); listener->Start(); • Socket connection = listener->AcceptSocket(); • NetworkStream ^socketStream = gcnew NetworkStream( connection ); BinaryWriter ^writer = gcnew BinaryWriter( socketStream ); BinaryReader ^reader = gcnew BinaryReader( socketStream ); • reader->ReadString() and writer->Write(); • writer->Close(); reader->Close(); socketStream->Close(); connection->Close(); • TcpClient ^client = gcnew TcpClient(); client->Connect( L"localhost", 12345 ) • NetworkStream ^clientStream = gcnew NetworkStream( client ); BinaryWriter ^writer = gcnew BinaryWriter( clientStream ); BinaryReader ^reader = gcnew BinaryReader( clientStream ); • reader->ReadString() and writer->Write(); • writer->Close(); reader->Close(); clientStream->Close(); client->Close();

  6. create socket, connect to hostid, port=x create listener socket, port=x, for incoming request: TcpClient ^client = gcnew TcpClient(); client->Connect(hostid, x); TcpListener ^listener = gcnew TcpListener(IPAddress::Any, x); listener->Start(); TCP connection setup wait for incoming connection request Socket connection = listener->AcceptSocket(); send request using Socket client read request from socket connection write reply to socket connection read reply from socket client Close socket connection Close socket client Client/server socket interaction: TCP Server (running on hostid) Client

  7. An Example • System::Environment::Exit(System::Environment::ExitCode ); • http://msdn.microsoft.com/en-us/library/system.environment.exit%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

More Related