简体   繁体   中英

How to send data over internet through console

I have to develop an application wherein I would receive data from parallel port and send it over to internet. This application is to be developed for embedded device running linux. Please suggest me how I can do that.

Regards

Sounds like a job for netcat . You can just open the device file and bind it straight to a TCP port: cat /dev/whatever | nc -l 2345 cat /dev/whatever | nc -l 2345 reads from a device and writes the results to a socket in case a client connects to port 2345.

If you need security, consider using a SSH tunnel.

Best solution - socat. It can read from file and send to any socket (tcp, udp, unix, ipv4, ipv6), redirect program output, stdout. Reverse operations also posible.

Local example: read file "test", and send it content to localhost:9999

socat OPEN:test TCP:localhost:9999

If you want monitor file content and make it read only

socat OPEN:test,rdonly,ignoreeof TCP:localhost:9999

in socat you not need bash, in cat|nc some form of shell required.

我推荐使用C的套接字。

我建议使用SSH或Telnet。

I would suggest using one of Perl, Python, or Ruby to do it if it has some processing to do.

Otherwise, if it is to use any console command, you can use curl or wget .

If you want to do it in C, perhaps because your embedded Linux doesn't have any of the shell tools and languages that other people have suggested, you need to look at the socket interface. The sequence of events is more or less:

  1. create a socket using socket()
  2. connect to a server using c onnect()
  3. send your data using send() , or write() and deal with anything that comes back the other way using recv() or read().
  4. close the socket using close() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM