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
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.
I recommend sockets using C.
I would suggest either SSH or 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:
- create a socket using socket()
- connect to a server using connect()
- send your data using send(), or write() and deal with anything that comes back the other way using recv() or read().
- close the socket using close().
精彩评论