Lecture on Sockets and Client/Server Programming

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/70

flashcard set

Earn XP

Description and Tags

These flashcards summarize the key concepts, functions, and details regarding sockets and client/server programming as covered in the lecture.

Last updated 1:45 AM on 4/15/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

71 Terms

1
New cards

What are sockets?

Sockets are an interface for programming network communication, allowing the construction of client/server applications.

2
New cards

What is a client/server application?

An application where a client program can invoke server programs with messages (requests) rather than shared data.

3
New cards

What is the primary function of a socket?

To implement message exchanges between processes running on different machines.

4
New cards

What protocol is used for connected mode communication?

TCP (Transmission Control Protocol) is used for connected mode communication.

5
New cards

What is the advantage of TCP?

TCP automatically handles communication problems and allows a stream of bytes.

6
New cards

What is a disadvantage of TCP?

TCP has a costly connection management procedure.

7
New cards

What is UDP?

UDP (User Datagram Protocol) is used for non-connected mode communication and is lightweight with less resource consumption.

8
New cards

What is a feature of UDP?

UDP allows broadcast and multicast communications.

9
New cards

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).

10
New cards

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.

11
New cards

What does the bind() function do?

It associates a socket with a local port and prepares it to receive messages.

12
New cards

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.

13
New cards

What is the purpose of the accept() function?

It blocks until a connection request is received, returning a new socket for the connection.

14
New cards

What is the difference between the functions send() and sendto()?

send() is used for connected mode, while sendto() is used for non-connected mode.

15
New cards

What happens after the client calls connect()?

A connection request is sent from the client to the server.

16
New cards

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.

17
New cards

What are the advantages of using sockets?

Sockets allow for fine-grained control over message exchanges between processes.

18
New cards

What common challenge do socket programmers face?

Programming with sockets can be verbose and error-prone.

19
New cards

What does the function listen() do?

It specifies the maximum number of pending connection requests the server is willing to accept.

20
New cards

Why is socket programming sometimes complex?

It involves managing state, dealing with errors, and ensuring reliable communication.

21
New cards

What is the Java package used for socket programming?

The java.net package.

22
New cards

What is InetAddress used for in Java?

InetAddress allows invoking DNS to translate machine names into IP addresses.

23
New cards

What happens when a server accepts a connection?

The server creates a new socket to communicate with the client.

24
New cards

What are streams in Java socket programming?

Streams are used for reading and writing data over sockets.

25
New cards

What class in Java allows sending and receiving objects over a socket?

ObjectOutputStream and ObjectInputStream allow serialization and deserialization of objects.

26
New cards

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.

27
New cards

What does serialization mean in Java?

Serialization translates an object into a byte stream for transferring it between remote hosts.

28
New cards

What is the role of the Slave class in the TCP example?

The Slave class represents a thread handling client connections.

29
New cards

How does the server respond to a client after accepting a connection?

The server can use InputStream and OutputStream of the socket for communication.

30
New cards

What is the significance of the @IP and #port in socket programming?

They identify a specific process on a machine for incoming communication.

31
New cards

What is the difference between InputStream and OutputStream?

InputStream is for reading bytes, while OutputStream is for writing bytes.

32
New cards

What are DatagramSocket and DatagramPacket used for?

They are used for UDP communications to send and receive data packets.

33
New cards

How can a UDP server read incoming messages?

A server can use the receive() method on a DatagramSocket.

34
New cards

What does the function recv() do?

It receives a message on a connected socket.

35
New cards

How do you handle multiple client connections in a server?

By forking a new process for each client connection.

36
New cards

What is the purpose of the flag parameter in send functions?

It specifies options to control the transmission parameters.

37
New cards

What does getHostByName() do in Java?

It performs a DNS lookup to get the IP address for a given hostname.

38
New cards

How can a client create a connection to a server in Java?

By instantiating a Socket object with the server's hostname and port.

39
New cards

What is a common error handling mechanism for sockets in Java?

Using try-catch blocks to handle IOException and UnknownHostException.

40
New cards

What is a concurrent server?

A server that can handle multiple connections simultaneously by creating a new process or thread for each connection.

41
New cards

What is the function of bcopy() in socket programming?

It copies the address obtained from DNS into the sockaddr structure.

42
New cards

What does the close() function do in socket programming?

It closes a socket, releasing the resources associated with it.

43
New cards

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.

44
New cards

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.

45
New cards

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.

46
New cards

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.

47
New cards

What does the printWriter class do?

It provides methods for formatted printing of data to an OutputStream.

48
New cards

What is a socket descriptor?

A unique identifier (file descriptor) for an open socket used in communication.

49
New cards

What is the main advantage of using threads in server programming?

Threads allow the server to handle multiple client requests concurrently.

50
New cards

What is error handling in socket programming?

Methods and practices used to manage and respond to runtime errors that occur during socket operations.

51
New cards

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.

52
New cards

What does sock_desc represent in socket API functions?

It represents the socket descriptor returned by socket() used for further operations.

53
New cards

How does a server notify the client after processing a request?

By sending a response message back to the client over the established connection.

54
New cards

How is a non-blocking server implemented?

By using asynchronous I/O or managing multiple requests using threading or forking.

55
New cards

What does the function read() do?

It reads data from a connected socket into a buffer.

56
New cards

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.

57
New cards

What would you find in a DatagramPacket object after receiving a message?

The data, sender's IP address, and port number.

58
New cards

What does the function listen() expect as its second parameter?

The maximum number of pending connections that can be queued.

59
New cards

What parameters does the connect() function require?

The socket descriptor, the server's IP address and port, and the size of the address structure.

60
New cards

What role does the Slave class play in the example?

It is a thread that handles individual client connections.

61
New cards

What is the main conclusion regarding socket programming?

While socket programming is straightforward, it can be complex and error-prone without higher-level abstractions.

62
New cards

What is one of the main challenges of socket programming?

Managing different states and ensuring reliable communication.

63
New cards

What does the term 'message-oriented middleware' refer to?

Design patterns and frameworks that facilitate communication between distributed applications.

64
New cards

What is the primary use of sockets in network programming?

To create network applications that communicate over the internet or local networks.

65
New cards

What are two main types of sockets?

Connected sockets (TCP) and non-connected sockets (UDP).

66
New cards

What is a typical socket programming setup?

Creating a socket, binding to a port, listening for connections, and accepting incoming client requests.

67
New cards

What do you need to perform before using send() and recv() functions?

Establish a connection with the server using connect() for TCP.

68
New cards

How does client wait for a server response using UDP?

By calling recvfrom() to wait for incoming messages.

69
New cards

Why might a developer choose to use UDP over TCP?

To achieve faster communication and lower latency at the expense of reliability.

70
New cards

What is the significance of the IP address and port in a bind()?

They define the local endpoint of the socket for receiving messages.

71
New cards

What are the basic components of socket programming in Java?

Creating sockets, obtaining input/output streams, and handling exceptions.