Network Programming Flashcards
Client Server architecture
The client/server architecture that is ubiquous in networking is implicit in the foregoing description of sockets.
how is client/server implmented in java with Sockets
2 types of sockets:
1) serversocket that waits for others computers to connect to it
2) client socket that is used to connect to a server socket on some other computer(has host,port number & IP address)
Once a socket has been created we can obtain input and output streams to read ad write data to it:
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
More info on server socket
The ServerSocket class is used to create a server socket that listens for incoming client connections.
It requires a port number to listen on
It has a method accept() which blocks until a client connection is received, returns an instance of Socket representing the connection.
What is communication protocol?
When applications communicate over sockets, a protocol is neccessary.
Protocols are a set of rules for what can be sent, when and how.
It defines a conversation that the client and server can have in order to exchange data.
e.g.HTML
In only the most basic cases is a protocol unnecessary (for example a server that does nothing except stream a bunch of bytes to every client that connects to it without expecting any request parameters or reply).
How can a multithreaded server be simply implemented
Start listening.
Receive connection from client.
Launch a new thread to service the client (when done the thread can close the connection and terminate itself).
Go back to listening.
Why single threathed servers are of limited value?
More then one client
A realistic server will not handle the incoming client requests on a single thread, but will spawn a new thread (or use an existing one from a pool) to service each incoming request
The main server thus spreads almost a lot of time waiting for connections and is busy for a shorter time than a connection request timeout
HTTP Protocol why is it si flexible and widely used?
HYPERTEXT TRANSFER PROTOCOL
designed for web servers
HTTP checks for updates(ITSELF-to check if new version avaliable AND ANTIVIRUS SOFTWARE)
HTTP offers simple mechanism for obtaining any kind of data with information