I am trying connect to serial adapter over TCP using socat.
This is something that is even covered in the official documentation and should (in theory) just work.
I first start the server
$ socat -d -d -d -x -v tcp-l:9000,reuseaddr,fork file:/dev/tty.usbserial-00000000,nonblock,raw,echo=0
socat[96183] I socat by Gerhard Rieger and contributors - see www.dest-unreach.org
socat[96183] I This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (rg/)
socat[96183] I This product includes software written by Tim Hudson (tjh@cryptsoft.com)
socat[96183] I setting option "so-reuseaddr" to 1
socat[96183] I setting option "fork" to 1
socat[96183] I socket(2, 1, 6) -> 5
socat[96183] I starting accept loop
socat[96183] N listening on LEN=16 AF=2 0.0.0.0:9000
I then send some data to the socket, but nc does not exit.
echo "Hello world" | nc localhost 9000
And while I see the connection getting accepted, no data is being transmitted by socat.
socat[96183] I accept(5, {2, LEN=16 AF=2 127.0.0.1:62079}, 16) -> 6
socat[96183] N accepting connection from LEN=16 AF=2 127.0.0.1:62079 on LEN=16 AF=2 127.0.0.1:9000
socat[96183] I permitting connection from LEN=16 AF=2 127.0.0.1:62079
socat[96183] N forked off child process 96196
socat[96183] I close(6)
socat[96183] I still listening
socat[96183] N listening on LEN=16 AF=2 0.0.0.0:9000
socat[96196] I just born: child process 96196
socat[96196] I close(4)
socat[96196] I close(3)
socat[96196] I just born: child process 96196
socat[96196] I close(5)
socat[96196] I setting option "o-nonblock" to 1
socat[96196] I setting option "raw"
socat[96196] I setting option "echo" to 0
socat[96196] N opening character device "/dev/tty.usbserial-00000000" for reading and writing
socat[96196] I open("/dev/tty.usbserial-00000000", 06, 0666) -> 5
socat[96196] I resolved and opened all sock addresses
socat[96196] N starting data transfer loop with FDs [6,6] and [5,5]
The server should at least print:
> 2023/04/24 17:15:14.000904245 length=12 from=0 to=11
48 65 6c 6c 6f 20 77 6f 72 6c 64 0a Hello world.
--
Hello world
but instead it stays silent.
Increasing the debug level even further this happens when the connection gets accepted:
socat[96487] D select -> (, 0x20, 0x0, 0x0, NULL/0.000000), 1
socat[96487] D accept(5, 0x16eeaac00, 0x16eeaa710)
socat[96487] I accept(5, {2, LEN=16 AF=2 127.0.0.1:62354}, 16) -> 6
socat[96487] D fcntl(6, 2, 1)
socat[96487] D fcntl() -> 0
socat[96487] D getpeername(6, 0x16eeaa990, 0x16eeaa6f4{108})
socat[96487] D getpeername(, {LEN=16 AF=2 127.0.0.1:62354}, {16}) -> 0
socat[96487] D getsockname(6, 0x16eeaa920, 0x16eeaa6f0{108})
socat[96487] D getsockname(, {LEN=16 AF=2 127.0.0.1:9000}, {16}) -> 0
socat[96487] N accepting connection from LEN=16 AF=2 127.0.0.1:62354 on LEN=16 AF=2 127.0.0.1:9000
socat[96487] I permitting connection from LEN=16 AF=2 127.0.0.1:62354
socat[96487] D sigprocmask(1, 0x100080000, 0x0)
socat[96487] D sigprocmask() -> 0
socat[96487] D fork()
socat[96487] D fork() -> 96493
socat[96487] N forked off child process 96493
socat[96487] I close(6)
socat[96487] D close() -> 0
socat[96487] D sigprocmask(2, 0x100080000, 0x0)
socat[96487] D sigprocmask() -> 0
socat[96487] I still listening
socat[96487] N listening on LEN=16 AF=2 0.0.0.0:9000
socat[96487] D select(6, &0x28, &0x0, &0x0, NULL/0.000000)
socat[96493] D fork() -> 0
socat[96493] D getpid()
socat[96493] D getpid() -> 96493
socat[96493] I just born: child process 96493
socat[96493] D setenv("SOCAT_PID", "0", 1)
socat[96493] D setenv() -> 0
socat[96493] I close(4)
socat[96493] D close() -> 0
socat[96493] I close(3)
socat[96493] D close() -> 0
socat[96493] D getpid()
socat[96493] D getpid() -> 96493
socat[96493] D sigprocmask(2, 0x100080000, 0x0)
socat[96493] D sigprocmask() -> 0
socat[96493] I just born: child process 96493
socat[96493] D setenv("SOCAT_PID", "96493", 1)
socat[96493] D setenv() -> 0
socat[96493] I close(5)
socat[96493] D close() -> 0
socat[96493] D setenv("SOCAT_SOCKADDR", "127.0.0.1", 1)
socat[96493] D setenv() -> 0
socat[96493] D setenv("SOCAT_SOCKPORT", "9000", 1)
socat[96493] D setenv() -> 0
socat[96493] D setenv("SOCAT_PEERADDR", "127.0.0.1", 1)
socat[96493] D setenv() -> 0
socat[96493] D setenv("SOCAT_PEERPORT", "62354", 1)
socat[96493] D setenv() -> 0
socat[96493] D xioopen("file:/dev/tty.usbserial-00000000,nonblock,raw,echo=0")
socat[96493] D calloc(1, 848)
socat[96493] D calloc() -> 0x13b005500
socat[96493] D malloc(1024)
socat[96493] D malloc() -> 0x13a808600
socat[96493] I setting option "o-nonblock" to 1
socat[96493] I setting option "raw"
socat[96493] I setting option "echo" to 0
socat[96493] D stat(/dev/tty.usbserial-00000000, 0x16eeaace0)
socat[96493] D stat(, {-1775528684,2849,020666,1,0,0,150994948,0,65536,0,...}) -> 0
socat[96493] N opening character device "/dev/tty.usbserial-00000000" for reading and writing
socat[96493] D open("/dev/tty.usbserial-00000000", 06, 0666)
socat[96493] I open("/dev/tty.usbserial-00000000", 06, 0666) -> 5
socat[96493] D isatty(5)
socat[96493] D isatty() -> 1
socat[96493] D tcgetattr(5, 0x13b005658)
socat[96493] D tcgetattr(, {00000000,00000000,00004b00,00000000, 9600,9600, 04,ff,ff,7f,17,15,12,ff,03,1c,1a,19,11,13,16,0f,01,00,14,ff}) -> 0
socat[96493] D tcgetattr(5, 0x100f94980)
socat[96493] D tcgetattr(, {00000000,00000000,00004b00,00000000, 9600,9600, 04,ff,ff,7f,17,15,12,ff,03,1c,1a,19,11,13,16,0f,01,00,14,ff}) -> 0
socat[96493] D tcsetattr(5, 1, {00000000,00000000,00004b00,00000000, 9600,9600, 04,ff,ff,7f,17,15,12,ff,03,1c,1a,19,11,13,16,0f,01,00,14,ff})
socat[96493] D tcsetattr() -> 0
socat[96493] D fcntl(5, 2, 1)
socat[96493] D fcntl() -> 0
socat[96493] I resolved and opened all sock addresses
socat[96493] D posix_memalign(0x16eeaae68, 16384, 16385)
socat[96493] D posix_memalign(...) -> 0
socat[96493] N starting data transfer loop with FDs [6,6] and [5,5]
socat[96493] D data loop: sock1->eof=0, sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}
socat[96493] D select(7, &0x60, &0x60, &0x0, NULL/0.000000)
socat[96493] D select -> (, 0x40, 0x40, 0x0, NULL/0.000000), 2
socat[96493] D data loop: sock1->eof=0, sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}
socat[96493] D select(6, &0x20, &0x20, &0x0, NULL/0.000000)
To reduce the complexity I also tried with a non-forking server:
socat[96591] D select -> (, 0x20, 0x0, 0x0, NULL/0.000000), 1
socat[96591] D accept(5, 0x16dbaac00, 0x16dbaa710)
socat[96591] I accept(5, {2, LEN=16 AF=2 127.0.0.1:62420}, 16) -> 6
socat[96591] D fcntl(6, 2, 1)
socat[96591] D fcntl() -> 0
socat[96591] D getpeername(6, 0x16dbaa990, 0x16dbaa6f4{108})
socat[96591] D getpeername(, {LEN=16 AF=2 127.0.0.1:62420}, {16}) -> 0
socat[96591] D getsockname(6, 0x16dbaa920, 0x16dbaa6f0{108})
socat[96591] D getsockname(, {LEN=16 AF=2 127.0.0.1:9000}, {16}) -> 0
socat[96591] N accepting connection from LEN=16 AF=2 127.0.0.1:62420 on LEN=16 AF=2 127.0.0.1:9000
socat[96591] I permitting connection from LEN=16 AF=2 127.0.0.1:62420
socat[96591] I close(5)
socat[96591] D close() -> 0
socat[96591] D setenv("SOCAT_SOCKADDR", "127.0.0.1", 1)
socat[96591] D setenv() -> 0
socat[96591] D setenv("SOCAT_SOCKPORT", "9000", 1)
socat[96591] D setenv() -> 0
socat[96591] D setenv("SOCAT_PEERADDR", "127.0.0.1", 1)
socat[96591] D setenv() -> 0
socat[96591] D setenv("SOCAT_PEERPORT", "62420", 1)
socat[96591] D setenv() -> 0
socat[96591] D xioopen("file:/dev/tty.usbserial-00000000,nonblock,raw,echo=0")
socat[96591] D calloc(1, 848)
socat[96591] D calloc() -> 0x14f004200
socat[96591] D malloc(1024)
socat[96591] D malloc() -> 0x14f808200
socat[96591] I setting option "o-nonblock" to 1
socat[96591] I setting option "raw"
socat[96591] I setting option "echo" to 0
socat[96591] D stat(/dev/tty.usbserial-00000000, 0x16dbaace0)
socat[96591] D stat(, {-1775528684,2849,020666,1,0,0,150994948,0,65536,0,...}) -> 0
socat[96591] N opening character device "/dev/tty.usbserial-00000000" for reading and writing
socat[96591] D open("/dev/tty.usbserial-00000000", 06, 0666)
socat[96591] I open("/dev/tty.usbserial-00000000", 06, 0666) -> 5
socat[96591] D isatty(5)
socat[96591] D isatty() -> 1
socat[96591] D tcgetattr(5, 0x14f004358)
socat[96591] D tcgetattr(, {00000000,00000000,00004b00,00000000, 9600,9600, 04,ff,ff,7f,17,15,12,ff,03,1c,1a,19,11,13,16,0f,01,00,14,ff}) -> 0
socat[96591] D tcgetattr(5, 0x102294980)
socat[96591] D tcgetattr(, {00000000,00000000,00004b00,00000000, 9600,9600, 04,ff,ff,7f,17,15,12,ff,03,1c,1a,19,11,13,16,0f,01,00,14,ff}) -> 0
socat[96591] D tcsetattr(5, 1, {00000000,00000000,00004b00,00000000, 9600,9600, 04,ff,ff,7f,17,15,12,ff,03,1c,1a,19,11,13,16,0f,01,00,14,ff})
socat[96591] D tcsetattr() -> 0
socat[96591] D fcntl(5, 2, 1)
socat[96591] D fcntl() -> 0
socat[96591] I resolved and opened all sock addresses
socat[96591] D posix_memalign(0x16dbaae68, 16384, 16385)
socat[96591] D posix_memalign(...) -> 0
socat[96591] N starting data transfer loop with FDs [6,6] and [5,5]
socat[96591] D data loop: sock1->eof=0, sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}
socat[96591] D select(7, &0x60, &0x60, &0x0, NULL/0.000000)
socat[96591] D select -> (, 0x40, 0x40, 0x0, NULL/0.000000), 2
socat[96591] D data loop: sock1->eof=0, sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}
socat[96591] D select(6, &0x20, &0x20, &0x0, NULL/0.000000)
Neither works as expected. I've tried other clients other than nc.
The usb adapter works just fine and acts as null modem with tx and rx connected.
Any pointers what I might be missing? I am trying this on macOS 12.6 but it should also work on linux.