Socket client in golang (TCP). Sockets is the raw network layer (TCP/UDP). Data is often transmitted using protocols, but sockets let you define your own protocols.
This example creates a socket client. A socket server needs to be running.
Learn How To Code: Google’s Go (golang) Programming Language
To use network sockets, load the net module. The net module lets you make network connections and transmit data.
A socket client does not specify a protocol, you can create your own protocol implementation if you want.
Sockets just let you send raw data from client to server and back.
Connects to the server with
// connect to server
Send and receive data with:
// send to server
This example connects to a network server. In this case, a socket server running ony your local computer.
In this example, the client connects to the server on port 8000, then sends a message the user tells and finally waits for a message.
(make sure your firewall isn’t blocking).
// socket client for golang