Although ServerSocket class is designed to generically listen for incoming connections, Can I just use a Socket object instead and retrieve incoming data in java? If yes, then is there any additional precautions that i need to take in doing so?
Edit: Thanks for the answers…but although in UDP there is only one socket class–DatagramSocket right?
The
ServerSocketis used to bind() and accept() to a local port. Despite the name,ServerSocketis not aSocket, it’s only used to receive the connection. Once that’s done, you get aSocketfrom accepting an incoming request, that is a communication pipe. I don’t believe you can use aSocketto receive incoming requests without using some sort of connection receiver likeServerSocket.