Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sockets A popular API for client-server interaction.

Similar presentations


Presentation on theme: "Sockets A popular API for client-server interaction."— Presentation transcript:

1 Sockets A popular API for client-server interaction

2 Complete view of a socket Application Presentation Session Transport Network Data Link Physical Application Presentation Session Transport Network Data Link Physical Applications talk to each other via APIs like sockets. Sockets provide the interface to the other layers.

3 Programmer View of a socket Application socket The networking aspects of a socket are transparent Similar to writing to and reading from a file

4 Socket API Three popular variations –berkley - older outdated unix API –TLI - newer unix version –winsock - microsoft All very similar Most examples in c but available in other languages

5 General Approach SERVER CLIENT Sets up a connection to wait for client (port) Asks for connection to server port Responds & sets up a different connection for the dialog Client asks for service Server responds time

6 Fundamental difference with your programming experience Your programs have predictable input output sequences. Typically defined by order of data in a file or which button was clicked. Can NOT control order in which peer queries or responds. Requires an event-driven paradigm

7 Event-driven apps While (NOT A TERMINATE EVENT) get next event if a reasonable event occurred process it else error or terminate Consider deadlocks: A waits for B to send a message X B waits for A to send message Y neither does -> deadlock! Like windows programs!

8 Problems with socket apps Timing problems are new for you Apps typically will deadlock Since input is less predictable, harder to debug. Will need to send/get info through socket and echo to a standard output device whatever is sent/read to aid in debugging

9 See socket code examples Check out examples on WWW www.pcs.cnu.edu/~dgame

10 Adapting the example to your problem Setup and disconnect is very similar Interaction is not as simple as the example read/write are basically executed in your main loop.

11 Non-socket APIs Other than the three types of sockets, one will typically find RPC in use. RPC stands for Remote Procedure Call RPC effectively extracts a function from your code and runs it on another machine X = sqrt(y) Calc sqrt(y) return results y x

12 Additional considerations Setting up and launching a server on your OS How many simultaneous servers can run How to handle queues of clients waiting for service


Download ppt "Sockets A popular API for client-server interaction."

Similar presentations


Ads by Google