How To Send Data To A Tcp Port
There are a number of protocols powering the Internet of Things. Choosing the correct one will depend on your projection's security, bandwidth and reliability needs, or maybe only your device computing limitations. In some cases like cellular transmission, the good one-time TCP/UDP package transmission will work just fine. This article volition show you how to simulate a client using a useful tool called Netcat and realize the immediate connexion using your own computer's terminal.
To learn how to ship data to Ubidots using these protocols, come across Send Data to Ubidots over TCP or UDP.
What is Netcat?
Netcat is a featured networking utility which reads and writes information across network connections, using the TCP/IP protocol. Designed to be a reliable "back-end" tool, Netcat tin be used directly with other programs and scripts to send files from a client to a server and dorsum. At the same fourth dimension, it is a feature-rich network debugging and exploration tool that can specify the network patameters while also establishing a connection to a remote host via a tunnel.
Although Netcat tin do many things, its main purpose and about desirable part is to:
-
Create an initial socket to establish a connexion from server to the client.
-
Once connected, Netcat volition automatically generate a second socket to transmit files from the server to the customer and visa versa. (This is the really absurd part.)
Reference below for a diagram of the data Netcat protocol architecture.
Something so uncomplicated happens to be extraordinarily powerful and flexible as you lot will run across below. For simplicity, local connections are used, although, of class, they can exist used between different machines.
Syntax
nc [-options] hostname port[s] [ports]
nc -l -p port [-options] [hostname] [port]
Basic parameters
-
-l: set the "mind" mode, waits for the incoming connections.
-
-p: local port
-
-u: prepare the UDP mode
Test your Netcat understanding equally a customer-server
Open two computer terminals, the first volition act equally the server and the 2nd will be the customer.
TCP client
With Netcat your PC can be converted in a server, y'all want to brainstorm equally a server that listens at port 2399:
$ nc -l 2399
In addition, we can use the server to connect to the port (2399) recently opened, from the client side:
$ nc localhost 2399
As you can meet on the image below, the connection is established:
With the connection established you are now able to write to the server from the client:
$ nc localhost 2399
Howdy Server
In the terminal where the server is running, your text files will appear seamlessly.
$ nc -l 2399
Howdy Server
UDP client
By default Netcat uses the TCP protocol for its communications, simply it tin can also UDP using the-u pick.
Equally we mentioned at the previous step, Netcat lets you convert your PC in a server. In this example we're going to establish the connexion between the server and the client but using UDP.
From the server side, run the command below. As you can see, the control establishes the UDP connectedness just requires the -u to be added to the command:
$ nc -u -l 2399
Once you start the server, establish the connectedness with the client:
$ nc -u localhost 2399
Now the client and the server are using UDP protocol for their communication. You can verify commincation using the netstat command in a new (tertiary) calculator terminal.
$ netstat
| grep
2399
udp 0 0 localhost:2399 localhost:57508 ESTABLISHED
As y'all tin encounter in the images below, the bulletin is received past the server, and the transmission is verified by the connectedness:
With this introduction to Netcat, you now have a better understanding of this advanced tool to ship data quickly and efficiently betwixt client and server. For additional information, check out this link.
Happy Hacking! :)
This article was originally published on Ubidots' Blog on June 22, 2017.
How To Send Data To A Tcp Port,
Source: http://help.ubidots.com/en/articles/937233-sending-tcp-udp-packets-using-netcat
Posted by: chadbourneanning.blogspot.com
0 Response to "How To Send Data To A Tcp Port"
Post a Comment