WorksheetsTCP Socket Programming
Total questions: 32
Worksheet time: 32mins
What is a socket in Go?
A type used to establish a network connection
A data structure used for file I/O operations
A synchronization primitive for concurrent programming
A function for dynamic memory allocation
Which package in Go provides functionality for socket programming?
fmt
net
os
sync
How can you create a TCP listener in Go?
net.ListenTCP()
net.DialTCP()
net.Listen()
net.Dial()
Which function is used to accept incoming connections in Go?
net.Accept()
net.Dial()
net.DialTCP()
net.AcceptTCP()
Which protocol is (are) commonly used with sockets in Go for network communication?
TCP
UDP
HTTP
FTP
What is the purpose of the net.Dial() function in Go?
To establish a connection to a remote address
To send data over a socket
To close a socket connection
To listen for incoming connections
Which function is used to get data from a socket connection in Go?
How can you push data to a socket connection in Go?
Which of the following is NOT a valid socket address format in Go?
Which of the following is an example of a valid IPv6 socket address in Go?
Which function is used to close a socket connection in Go?
conn.Close()
conn.Shutdown()
conn.Disconnect()
conn.End()
What is the purpose of the bind() function in TCP socket programming?
To associate a socket with a specific IP address and port
To send data over a socket
To close a socket connection
To listen for incoming connections
Which of the following statements about TCP socket programming is true?
TCP provides reliable, ordered, and error-checked delivery of data.
TCP is connectionless and operates on a best-effort basis.
TCP is a low-level protocol used for physical network communication.
TCP is primarily used for real-time streaming applications.
What is the purpose of the net.Conn interface in Go TCP socket programming?
To represent a TCP listener
To represent a TCP connection
To represent a UDP connection
To represent a network address
How can you set a timeout for TCP socket operations in Go?
Using the SetTimeout() function
By passing a context with a timeout to socket functions
By specifying the timeout in the TCP address
By using the time.Sleep() function
What is the purpose of the net.ResolveTCPAddr() function in Go?
To resolve a domain name to an IP address
To resolve a TCP address from a string representation
To establish a TCP connection
To close a TCP connection
Which of the following statements about TCP socket programming in Go is true?
Go provides a high-level abstraction for TCP socket programming.
Go only supports UDP socket programming.
Go does not have built-in support for TCP socket programming.
Go relies on external libraries for TCP socket programming.
What is the purpose of the net.DialTimeout() function in Go?
To establish a TCP connection with a timeout
To set the timeout for read operations on a TCP connection
To set the timeout for write operations on a TCP connection
All of above
What is the purpose of the net.SplitHostPort() function in Go?
To split a TCP address into its host and port components
To split a string into its host and port components
To split a domain name into its host and port components
To split a URL into its host and port components
Which function is used to resolve a domain name to an IP address in Go?
net.LookupIP()
net.ResolveIPAddr()
net.ResolveTCPAddr()
net.LookupTCPAddr()
How can you determine the number of bytes that have been sent over a TCP connection in Go?
By calling the conn.BytesSent() function
By checking the conn.SentBytes field
By calling the conn.SetBytesSent() function
By checking the value return by conn.Write()
Which of the following statements about TCP socket programming in Go is true?
Go uses goroutines to handle concurrent connections.
Go only supports blocking I/O for TCP socket programming.
Go does not provide functions for reading and writing binary data over TCP
All of above
How can you set the read and write buffer sizes for a TCP connection in Go?
By calling the conn.SetBufferSize() function
By setting the conn.ReadBufferSize and conn.WriteBufferSize fields
By calling the conn.SetReadBuffer() and conn.SetWriteBuffer() functions
By setting the conn.BufferSize field
How can you handle multiple concurrent connections in Go TCP socket programming?
By using a single goroutine for all connections
By creating a new goroutine for each connection
By using a mutex to synchronize access to the connection
By setting a global flag to manage connections
What is the result of the following code?
Prints "Hello, server!"
Fails to compile due to an error
Prints an empty string
Hangs indefinitely
What is the result of the following code? Assume the client echoes back the server data
Prints "Hello, client!"
Fails to compile due to an error
Prints an empty string
Hangs indefinitely
What is the purpose of SetReadDeadLine in the code above?
Cause the program fail to compile
The program will hang for one second
Data must be received within one second
The client will sleep for one second
What is the result of the following code?
Prints the accepted connection information
Fails to compile due to an error
Prints an error message
Hangs indefinitely
What is the result of the following code?
Prints the deadline set for the connection
Fails to compile due to an error
Prints an error message
Prints a boolean value indicating the success of setting the deadline
What is the result of the following code?
Prints the local address of the client connection
Fails to compile due to an error
Prints the remote address of the client connection
Prints an empty string
What is the result of the following code?
Prints the local address of the server listener
Fails to compile due to an error
Prints the remote address of the server listener
Prints an empty string
What is the result of the following code?
Prints the data received from the client
Fails to compile due to an error
Prints an empty string
Hangs indefinitely
