Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

TCP Socket Programming

Total questions: 32

Worksheet time: 32mins

Name
Class
Date
1.

What is a socket in Go?

a)

A type used to establish a network connection

b)

A data structure used for file I/O operations

c)

A synchronization primitive for concurrent programming

d)

A function for dynamic memory allocation

2.

Which package in Go provides functionality for socket programming?

a)

fmt

b)

net

c)

os

d)

sync

3.

How can you create a TCP listener in Go?

a)

net.ListenTCP()

b)

net.DialTCP()

c)

net.Listen()

d)

net.Dial()

4.

Which function is used to accept incoming connections in Go?

a)

net.Accept()

b)

net.Dial()

c)

net.DialTCP()

d)

net.AcceptTCP()

5.

Which protocol is (are) commonly used with sockets in Go for network communication?

a)

TCP

b)

UDP

c)

HTTP

d)

FTP

6.

What is the purpose of the net.Dial() function in Go?

a)

To establish a connection to a remote address

b)

To send data over a socket

c)

To close a socket connection

d)

To listen for incoming connections

7.

Which function is used to get data from a socket connection in Go?

b)

conn.Write()

c)

conn.Dial()

d)

conn.Accept()

8.

How can you push data to a socket connection in Go?

a)

conn.Send()

b)

conn.Write()

d)

conn.Accept()

9.

Which of the following is NOT a valid socket address format in Go?

b)

192.168.1.1:9000

c)

192.168.1.1

d)

All of above are valid

10.

Which of the following is an example of a valid IPv6 socket address in Go?

b)

192.168.1.1:9000

c)

[::1]:8080

d)

All of above

11.

Which function is used to close a socket connection in Go?

a)

conn.Close()

b)

conn.Shutdown()

c)

conn.Disconnect()

d)

conn.End()

12.

What is the purpose of the bind() function in TCP socket programming?

a)

To associate a socket with a specific IP address and port

b)

To send data over a socket

c)

To close a socket connection

d)

To listen for incoming connections

13.

Which of the following statements about TCP socket programming is true?

a)

TCP provides reliable, ordered, and error-checked delivery of data.

b)

TCP is connectionless and operates on a best-effort basis.

c)

TCP is a low-level protocol used for physical network communication.

d)

TCP is primarily used for real-time streaming applications.

14.

What is the purpose of the net.Conn interface in Go TCP socket programming?

a)

To represent a TCP listener

b)

To represent a TCP connection

c)

To represent a UDP connection

d)

To represent a network address

15.

How can you set a timeout for TCP socket operations in Go?

a)

Using the SetTimeout() function

b)

By passing a context with a timeout to socket functions

c)

By specifying the timeout in the TCP address

d)

By using the time.Sleep() function

16.

What is the purpose of the net.ResolveTCPAddr() function in Go?

a)

To resolve a domain name to an IP address

b)

To resolve a TCP address from a string representation

c)

To establish a TCP connection

d)

To close a TCP connection

17.

Which of the following statements about TCP socket programming in Go is true?

a)

Go provides a high-level abstraction for TCP socket programming.

b)

Go only supports UDP socket programming.

c)

Go does not have built-in support for TCP socket programming.

d)

Go relies on external libraries for TCP socket programming.

18.

What is the purpose of the net.DialTimeout() function in Go?

a)

To establish a TCP connection with a timeout

b)

To set the timeout for read operations on a TCP connection

c)

To set the timeout for write operations on a TCP connection

d)

All of above

19.

What is the purpose of the net.SplitHostPort() function in Go?

a)

To split a TCP address into its host and port components

b)

To split a string into its host and port components

c)

To split a domain name into its host and port components

d)

To split a URL into its host and port components

20.

Which function is used to resolve a domain name to an IP address in Go?

a)

net.LookupIP()

b)

net.ResolveIPAddr()

c)

net.ResolveTCPAddr()

d)

net.LookupTCPAddr()

21.

How can you determine the number of bytes that have been sent over a TCP connection in Go?

a)

By calling the conn.BytesSent() function

b)

By checking the conn.SentBytes field

c)

By calling the conn.SetBytesSent() function

d)

By checking the value return by conn.Write()

22.

Which of the following statements about TCP socket programming in Go is true?

a)

Go uses goroutines to handle concurrent connections.

b)

Go only supports blocking I/O for TCP socket programming.

c)

Go does not provide functions for reading and writing binary data over TCP

d)

All of above

23.

How can you set the read and write buffer sizes for a TCP connection in Go?

a)

By calling the conn.SetBufferSize() function

b)

By setting the conn.ReadBufferSize and conn.WriteBufferSize fields

c)

By calling the conn.SetReadBuffer() and conn.SetWriteBuffer() functions

d)

By setting the conn.BufferSize field

24.

How can you handle multiple concurrent connections in Go TCP socket programming?

a)

By using a single goroutine for all connections

b)

By creating a new goroutine for each connection

c)

By using a mutex to synchronize access to the connection

d)

By setting a global flag to manage connections

25.

What is the result of the following code?

a)

Prints "Hello, server!"

b)

Fails to compile due to an error

c)

Prints an empty string

d)

Hangs indefinitely

26.

What is the result of the following code? Assume the client echoes back the server data

a)

Prints "Hello, client!"

b)

Fails to compile due to an error

c)

Prints an empty string

d)

Hangs indefinitely

27.

What is the purpose of SetReadDeadLine in the code above?

a)

Cause the program fail to compile

b)

The program will hang for one second

c)

Data must be received within one second

d)

The client will sleep for one second

28.

What is the result of the following code?

a)

Prints the accepted connection information

b)

Fails to compile due to an error

c)

Prints an error message

d)

Hangs indefinitely

29.

What is the result of the following code?

a)

Prints the deadline set for the connection

b)

Fails to compile due to an error

c)

Prints an error message

d)

Prints a boolean value indicating the success of setting the deadline

30.

What is the result of the following code?

a)

Prints the local address of the client connection

b)

Fails to compile due to an error

c)

Prints the remote address of the client connection

d)

Prints an empty string

31.

What is the result of the following code?

a)

Prints the local address of the server listener

b)

Fails to compile due to an error

c)

Prints the remote address of the server listener

d)

Prints an empty string

32.

What is the result of the following code?

a)

Prints the data received from the client

b)

Fails to compile due to an error

c)

Prints an empty string

d)

Hangs indefinitely