This article is for when you want to perform socket communication quickly for testing, and you want to perform socket communication using the command used from the terminal of linux (ubuntu), nc command (netcat).
If you want to know the detailed options of nc command, please refer to the following article. https://qiita.com/hana_shin/items/97e6c03ac5e5ed67ce38
As the configuration, we will explain the commands and communication methods on the TCP server, TCP client, UDP server, and UDP client. Also, since the command options are different between ipv4 and ipv6, they are also shown separately.
I hope that it can be used by those who want to easily test and check the operation of socket communication.
TCP server
ipv4
nc -l 8888
ipv6
nc -6 -l 8888
--After executing the above command, specify the IP address of the network interface you are using. Start the server on the port (8888 is the port number above).
--When you issue a command, it will be in the data reception waiting state. When the data is received normally, the received data will be displayed on the terminal.
TCP client
ipv4
nc -p 8888 xx.xx.xx.xx 8888
ipv6
nc -6 -p 8888 xxxx::xxxx:xxxx:xxxx:xxxx 8888
--After executing the above command, start the client on the specified port (8888 is the port number in the above case). Then, it connects to port 8888 of the specified ip address (xx.xx.xx.xx for ipv4, xxxx :: xxxx: xxxx: xxxx: xxxx for ipv6).
--After executing the command, you will be waiting for input of transmission data, so enter the character string in the terminal and press Enter to send the character string data to the specified port of the specified IP address.
UDP server
ipv4
nc -u -l 8888
ipv6
nc -6 -u -l 8888
--After executing the above command, specify the IP address of the network interface you are using. Start the server on the port (8888 is the port number above)
--When you receive data, the received data is displayed.
UDP client
ipv4
nc -u -p 8888 xx.xx.xx.xx 8888
ipv6
nc -6 -u -p 8888 xxxx::xxxx:xxxx:xxxx:xxxx 8888
--After executing the above command, start the client on the specified port (8888 is the port number in the above case). Then, it connects to port 8888 of the specified ip address (xx.xx.xx.xx for ipv4, xxxx :: xxxx: xxxx: xxxx: xxxx for ipv6).
--After executing the command, you will be waiting for input of transmission data, so enter the character string in the terminal and press Enter to send the character string data to the specified port of the specified IP address.
Recommended Posts