There's already a working server service via socket, and I would like to test it via netcat. I'm using Mac OS X Lion. Currently, I'm able to connect to server via port, to send packet, but the packet contains wrong value. Here are the details:
I need to send 'm' symbol to the server and the server will return 00000000, a zero byte as a response. Server guy told me, server receives 'A0' when I'm sending 'm', and server receives '313039A' when I'm sending '109'. How to define sending format or something, I just need to send 'm' (01101101)?
To send bytes, you just type the ASCII character to get that byte. If the byte you need to send is less that the type-able characters, you hold Ctrl down to subtract 64 off of the ASCII value. Run: telnet 127.0. 0.1 1234 to connect, then press Ctrl+D to send 0x04 (since D is 0x68).
On one machine, you can tell netcat to listen to a specific port for connections. We can do this by providing the -l parameter and choosing a port: netcat -l 4444.
You can send just "m" with
echo -n 'm' | nc <server> <port>
You can easily check what you're sending on your local machine:
# in one Terminal start the listener:
$ nc -l 1234 | hexdump -C
00000000 6d |m|
00000001
# in other Terminal send the packet:
$ echo -n 'm' | nc 127.0.0.1 1234
nc will happily send/receive NUL bytes - there is no problem with that:
# sending side
$ echo -n X | tr X '\000' | nc 127.0.0.1 1234
# receiving side
$ nc -l 1234 | hexdump -C
00000000 00 |.|
00000001
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With