Computer Networks Questions & Answers – Socket Programming

This set of Computer Networks Assessment Questions and Answers focuses on “Socket Programming”.

1. Which methods are commonly used in Server Socket class?
a) Public Output Stream get Output Stream ()
b) Public Socket accept ()
c) Public synchronized void close ()
d) Public void connect ()
View Answer

Answer: b
Explanation: The Public socket accept () method is used by the ServerSocket class to accept the connection request of exactly one client at a time. The client requests by initializing the socket object with the servers IP address.

2. Which constructor of Datagram Socket class is used to create a datagram socket and binds it with the given Port Number?
a) Datagram Socket(int port)
b) Datagram Socket(int port, Int Address address)
c) Datagram Socket()
d) Datagram Socket(int address)
View Answer

Answer: b
Explanation: Datagram Socket (int port, Int Address address) is used to create a datagram socket. A datagram socket is created for connection-less communication between the server and the client. There is no accept() method in this class.

3. The client in socket programming must know which information?
a) IP address of Server
b) Port number
c) Both IP address of Server & Port number
d) Only its own IP address
View Answer

Answer: c
Explanation: The client in socket programming must know IP address of Server as it has to use that IP address in order to initialize the socket class constructor. That is how the client requests a connection to the server.
advertisement
advertisement

4. The URL Connection class can be used to read and write data to the specified resource that is referred by the URL.
a) True
b) False
View Answer

Answer: a
Explanation: The URL Connection class can be used to read and write data to the specified resource referred by the URL. A connection to the URL is initialized by the OpenConnection() method of the class.

5. Datagram is basically just a piece of information but there is no guarantee of its content, arrival or arrival time.
a) True
b) False
View Answer

Answer: a
Explanation: Datagram is basically some information travelling between the sender and the receiver, but there is no guarantee of its content, arrival or arrival time. A Datagram socket class object is created to make a datagram connection between the server and the client.

6. TCP, FTP, Telnet, SMTP, POP etc. are examples of ___________
a) Socket
b) IP Address
c) Protocol
d) MAC Address
View Answer

Answer: c
Explanation: TCP, FTP, Telnet, SMTP, POP etc. are examples of Protocol. Out of them, TCP is a transport layer protocol and FTP, TELNET, SMTP and POP are application layer protocols.

7. What does the java.net.InetAddress class represent?
a) Socket
b) IP Address
c) Protocol
d) MAC Address
View Answer

Answer: b
Explanation: The java.net.InetAddress class represents IP Address of a particular specified host. It can be used to resolve the host name from the IP address or the IP address from the host name.
advertisement

8. The flush () method of Print Stream class flushes any un-cleared buffers in the memory.
a) True
b) False
View Answer

Answer: a
Explanation: The flush () method of Print Stream class flushes any un cleared buffers in memory.

9. Which classes are used for connection-less socket programming?
a) Datagram Socket
b) Datagram Packet
c) Both Datagram Socket & Datagram Packet
d) Server Socket
View Answer

Answer: c
Explanation: Datagram is basically some information travelling between the sender and the receiver, but there is no guarantee of its content, arrival or arrival time. Datagram Socket, Datagram Packet are used for connection-less socket programming, while Server Socket is used for connection-oriented socket programming.
advertisement

10. In Inet Address class, which method returns the host name of the IP Address?
a) Public String get Hostname()
b) Public String getHostAddress()
c) Public static InetAddress get Localhost()
d) Public getByName()
View Answer

Answer: a
Explanation: In Inet Address class public String getHostname() method returns the host name of the IP Address. The getHostAddress() method returns the IP address of the given host name.

Sanfoundry Global Education & Learning Series – Computer Networks.

To practice all areas of Computer Networks Assessment Questions, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.