Your task is to build a Go program server.go with a listener TCP server socket that can handle multiple simultaneous client connections. Below is an initial code template for the server socket; your objective is to write the additional required code to:
- Set the constant values
protocol = "tcp",address = "127.0.0.1", andport = ":12345". - Initiate a
listenerTCP server socket using the above constants and ensure youdeferclosing it to release resources. - Continuously listen and accept incoming client connection(s).
- Use a goroutine to handle each incoming client connection, allowing multiple simultaneous connections.
- Read the message from the client(s) and print it to the console.
- Send back to the client a fixed response message.
- Close each client connection after the interaction is completed.
DO NOT MODIFY the
main() function; within it, the program will take a clientAmount and a message as input, and pass them to the hidden simulateClientsConnecting() function to start the process of multiple clients connecting.