socat: tunnel IP through TTY
Ha-ha, I works but there needs to be some magic :)
So, configure the 1st peer with:
PC1:
1) slattach -L -s 57600 -p slip /dev/ttyUSB0 &
2) ifconfig sl0 up
3) socat TUN:192.168.1.1/24,up INTERFACE:sl0 &
... and something like that on the 2nd peer:
PC2:
1) slattach -L -s 57600 -p slip /dev/ttyUSB0 &
2) ifconfig sl0 up
3) socat TUN:192.168.1.2/24,up INTERFACE:sl0 &
And now, you can successfully ping one PC from another:
PC1:
1) ping -c 5 192.168.1.2
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
64 bytes from 192.168.1.2: icmp_req=1 ttl=64 time=348 ms
64 bytes from 192.168.1.2: icmp_req=2 ttl=64 time=551 ms
64 bytes from 192.168.1.2: icmp_req=3 ttl=64 time=557 ms
64 bytes from 192.168.1.2: icmp_req=4 ttl=64 time=549 ms
64 bytes from 192.168.1.2: icmp_req=5 ttl=64 time=348 ms
--- 192.168.1.2 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4003ms
rtt min/avg/max/mdev = 348.116/471.143/557.128/100.177 ms
It's a little bit tricky because of slattach
use but in fact any other solution must use something like slip to organize framing over the serial line. For example, PPP use HDLC-like frames.
socat with a virtual tty link and fork removes my pty link
Okay, I seem to have found a solution for myself. You have to create a virtual null modem pair first, then open one end of the virtual null modem pair and link it with the TCP listener.
socat -d -d PTY,raw,echo=0,link=/dev/ttyVA00 PTY,raw,echo=0,link=/dev/ttyVB00
Then
socat -d -d open:/dev/ttyVA00,nonblock,echo=0,raw TCP-LISTEN:11313,reuseaddr,fork
I can connect as many clients as I want, and everything seems to be working.
IP tunnel over Linux serial default shell
On a normal linux, you could use socat
.
This program allows you to connect several stream types (file, socket, tcp, udp, ...). In your case it would be tcp to file or more precisely a tcp socket at port xx to /dev/ttyUSB1. You should launch socat on both sides to build a tunnel.
Edit 1:
Sorry I got also disappointed by socat. I can't find a solution that keeps my TCP listener active for multiple successive connections, but handles only one connection at a time.
My solution is a simple C# program that uses 4 threads:
1. wait for input on stdin e.g. exit command
2. the TCP listener
3. the TCP worker thread for a active connection
4. if TCP is open, it opens another thread for COM
Thread 3 reads from TCP and writes to COM and Tread 4 reads from COM and writes to TCP. If thread gets a TCP close event, it stops thread 4, which closes COMx, and exits it self. Now thread 2 can accept a new connection. If thread 1 reads exit on stdin, it passes a message to all threads to stop and shutdown.
Maybe you can implement such a short program in C with pthreads on your embedded system, which has no socat.
The EOF problem:
I tried to google for a program that escapes a special character or reencodes a data stream from ASCII to ANSI or base64 or whatever.... If you can find such a program or write it also in C you can pipe it in between
Server <=> reencode <=> socat <--serial--> socat <=> reencode <=> client
Related Topics
Multiplication with Expr in Shell Script
How to Use Netcat for Windows to Send a Binary File to a Tcp Connection
Using Gnu/Linux System Call 'Splice' for Zero-Copy Socket to Socket Data Transfers in Haskell
Linux How to Copy But Not Overwrite
How to Paste Multi-Line Bash Codes into Terminal and Run It All at Once
How to List Library Dependencies of a Non-Native Binary
Linux Pipe Audio File to Microphone Input
What's the Best Way to Distribute a Binary Application for Linux
Linux Process in Background - "Stopped" in Jobs
Add Margin to PDF File When Merging Using Pdftk or Similar
Error While Installing Dbd::Oracle
Asp.Net Core Environment Variable Colon in Linux
Change Gnome Terminal Theme Programmatically
Upper Limit of File Descriptor in Linux
What Is The Significance of This_Module in Linux Kernel Module Drivers