Networking OSI Open Systems Interconnection model of computer

  • Slides: 7
Download presentation
Networking • OSI (Open Systems Interconnection) model of computer networking, seven layers (the Application,

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 process socket application process transport network link physical Internet link physical controlled by app developer controlled by OS

Networking • TCP/IP (Transmission Control Protocol/Internet Protocol) – reliable, byte stream-oriented (reliable transfer of

Networking • TCP/IP (Transmission Control Protocol/Internet Protocol) – reliable, byte stream-oriented (reliable transfer of bytes from 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

Socket programming with TCP client must contact server • server process must first be

Socket programming with TCP 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: TCP provides reliable, in-order byte-stream transfer (“pipe”) between client and server

TCP Socket Communications Client Server Listener Socket (Thread) Connect Client Socket (Thread) Accept Communicate

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

TCP Sockets in C++/CLI Client Server • • • Tcp. Listener ^listener = gcnew

TCP Sockets in C++/CLI Client Server • • • Tcp. Listener ^listener = gcnew Tcp. Listener(IPAddress: : Any, 12345); listener->Start(); Socket connection = listener>Accept. Socket(); Network. Stream ^socket. Stream = gcnew Network. Stream( connection ); Binary. Writer ^writer = gcnew Binary. Writer( socket. Stream ); Binary. Reader ^reader = gcnew Binary. Reader( socket. Stream ); reader->Read. String() and writer>Write(); writer->Close(); reader->Close(); socket. Stream->Close(); connection>Close(); • • • Tcp. Client ^client = gcnew Tcp. Client(); client->Connect( L"localhost", 12345 ) Network. Stream ^client. Stream = gcnew Network. Stream( client ); Binary. Writer ^writer = gcnew Binary. Writer( client. Stream ); Binary. Reader ^reader = gcnew Binary. Reader( client. Stream ); reader->Read. String() and writer>Write(); writer->Close(); reader->Close(); client. Stream->Close(); client>Close();

Client/server socket interaction: TCP Server (running on hostid) Client create listener socket, port=x, for

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

An Example • System: : Environment: : Exit(System: : Environment: : Exit. Code );

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