1/70
These flashcards summarize the key concepts, functions, and details regarding sockets and client/server programming as covered in the lecture.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What are sockets?
Sockets are an interface for programming network communication, allowing the construction of client/server applications.
What is a client/server application?
An application where a client program can invoke server programs with messages (requests) rather than shared data.
What is the primary function of a socket?
To implement message exchanges between processes running on different machines.
What protocol is used for connected mode communication?
TCP (Transmission Control Protocol) is used for connected mode communication.
What is the advantage of TCP?
TCP automatically handles communication problems and allows a stream of bytes.
What is a disadvantage of TCP?
TCP has a costly connection management procedure.
What is UDP?
UDP (User Datagram Protocol) is used for non-connected mode communication and is lightweight with less resource consumption.
What is a feature of UDP?
UDP allows broadcast and multicast communications.
How does a socket identify a process on a machine?
A process is identified by a combination of an IP address (@IP) and a port number (#port).
What are the main functions of the socket API?
The socket API includes creating a socket, opening a dialog, transferring data, and closing the dialog.
What does the bind() function do?
It associates a socket with a local port and prepares it to receive messages.
What must a server do before it can accept connections?
The server must call bind() to associate its socket with a local port and listen() to specify how many connections can be pending.
What is the purpose of the accept() function?
It blocks until a connection request is received, returning a new socket for the connection.
What is the difference between the functions send() and sendto()?
send() is used for connected mode, while sendto() is used for non-connected mode.
What happens after the client calls connect()?
A connection request is sent from the client to the server.
How does a client send data to a server using UDP?
The client uses the sendto() function and specifies the IP address and port of the server.
What are the advantages of using sockets?
Sockets allow for fine-grained control over message exchanges between processes.
What common challenge do socket programmers face?
Programming with sockets can be verbose and error-prone.
What does the function listen() do?
It specifies the maximum number of pending connection requests the server is willing to accept.
Why is socket programming sometimes complex?
It involves managing state, dealing with errors, and ensuring reliable communication.
What is the Java package used for socket programming?
The java.net package.
What is InetAddress used for in Java?
InetAddress allows invoking DNS to translate machine names into IP addresses.
What happens when a server accepts a connection?
The server creates a new socket to communicate with the client.
What are streams in Java socket programming?
Streams are used for reading and writing data over sockets.
What class in Java allows sending and receiving objects over a socket?
ObjectOutputStream and ObjectInputStream allow serialization and deserialization of objects.
How does a child process handle connections in a concurrent server?
The child process handles the connection and can manage its own socket, while the parent continues to accept new connections.
What does serialization mean in Java?
Serialization translates an object into a byte stream for transferring it between remote hosts.
What is the role of the Slave class in the TCP example?
The Slave class represents a thread handling client connections.
How does the server respond to a client after accepting a connection?
The server can use InputStream and OutputStream of the socket for communication.
What is the significance of the @IP and #port in socket programming?
They identify a specific process on a machine for incoming communication.
What is the difference between InputStream and OutputStream?
InputStream is for reading bytes, while OutputStream is for writing bytes.
What are DatagramSocket and DatagramPacket used for?
They are used for UDP communications to send and receive data packets.
How can a UDP server read incoming messages?
A server can use the receive() method on a DatagramSocket.
What does the function recv() do?
It receives a message on a connected socket.
How do you handle multiple client connections in a server?
By forking a new process for each client connection.
What is the purpose of the flag parameter in send functions?
It specifies options to control the transmission parameters.
What does getHostByName() do in Java?
It performs a DNS lookup to get the IP address for a given hostname.
How can a client create a connection to a server in Java?
By instantiating a Socket object with the server's hostname and port.
What is a common error handling mechanism for sockets in Java?
Using try-catch blocks to handle IOException and UnknownHostException.
What is a concurrent server?
A server that can handle multiple connections simultaneously by creating a new process or thread for each connection.
What is the function of bcopy() in socket programming?
It copies the address obtained from DNS into the sockaddr structure.
What does the close() function do in socket programming?
It closes a socket, releasing the resources associated with it.
What is the difference between blocking and non-blocking sockets?
Blocking sockets wait (block) for an operation to complete, while non-blocking sockets allow other operations to continue.
What happens to messages that are not received when using UDP?
There are no guarantees for message reception, and the application must handle possible message loss.
How is a TCP connection established between client and server?
The client sends a connection request, and the server accepts it after binding and listening.
What are the basic steps for setting up a server socket in Java?
Create a ServerSocket instance, bind it to a port, and call accept() to wait for client connections.
What does the printWriter class do?
It provides methods for formatted printing of data to an OutputStream.
What is a socket descriptor?
A unique identifier (file descriptor) for an open socket used in communication.
What is the main advantage of using threads in server programming?
Threads allow the server to handle multiple client requests concurrently.
What is error handling in socket programming?
Methods and practices used to manage and respond to runtime errors that occur during socket operations.
What is the function of DatagramPacket in UDP communication?
It's used to encapsulate the data being sent or received, along with the destination or sender's address.
What does sock_desc represent in socket API functions?
It represents the socket descriptor returned by socket() used for further operations.
How does a server notify the client after processing a request?
By sending a response message back to the client over the established connection.
How is a non-blocking server implemented?
By using asynchronous I/O or managing multiple requests using threading or forking.
What does the function read() do?
It reads data from a connected socket into a buffer.
What are the requirements for a class to be serializable in Java?
The class must implement the Serializable interface and should not reference non-Serializable objects.
What would you find in a DatagramPacket object after receiving a message?
The data, sender's IP address, and port number.
What does the function listen() expect as its second parameter?
The maximum number of pending connections that can be queued.
What parameters does the connect() function require?
The socket descriptor, the server's IP address and port, and the size of the address structure.
What role does the Slave class play in the example?
It is a thread that handles individual client connections.
What is the main conclusion regarding socket programming?
While socket programming is straightforward, it can be complex and error-prone without higher-level abstractions.
What is one of the main challenges of socket programming?
Managing different states and ensuring reliable communication.
What does the term 'message-oriented middleware' refer to?
Design patterns and frameworks that facilitate communication between distributed applications.
What is the primary use of sockets in network programming?
To create network applications that communicate over the internet or local networks.
What are two main types of sockets?
Connected sockets (TCP) and non-connected sockets (UDP).
What is a typical socket programming setup?
Creating a socket, binding to a port, listening for connections, and accepting incoming client requests.
What do you need to perform before using send() and recv() functions?
Establish a connection with the server using connect() for TCP.
How does client wait for a server response using UDP?
By calling recvfrom() to wait for incoming messages.
Why might a developer choose to use UDP over TCP?
To achieve faster communication and lower latency at the expense of reliability.
What is the significance of the IP address and port in a bind()?
They define the local endpoint of the socket for receiving messages.
What are the basic components of socket programming in Java?
Creating sockets, obtaining input/output streams, and handling exceptions.