How can I send a byte (or bytes) to test a socket listening in my application? [closed]
Asked Answered
E

1

13

How can I send a byte (or bytes) to test a TCP socket that's listening on a port in my application? My application receives a single byte that tells it what to do. Some operations will receive additional bytes to further instruct it.

I tried using Telnet already, but when I input the int value, it seems to send the int (4 bytes).

I just need to send a single byte (8 bits), instead of a sequence of 4 bytes. Is there an easy way to test my socket application? Should I just create another application to test it?

Eton answered 27/9, 2013 at 8:57 Comment(3)
Since this question is closed right now (I edited and voted to reopen), here is my answer. You can use nc (on Linux, Cygwin, MobaXterm, etc.) and send a byte: echo -e '\x04' | nc 127.0.0.1 1234Diestock
Two send 2 bytes (or more) you can use: echo -e '\x04''\x03' | nc 127.0.0.1 1234Diestock
You can also do it with Telnet! 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).Diestock
V
15

You should not be using telnet for this.

Better option is to use netcat.

Then, pipe your command through bash

EG.

echo -n 0x03 | nc 127.0.0.1 1234

Veda answered 27/9, 2013 at 9:18 Comment(1)
I use following lines: echo -e "\x30" | nc 127.0.0.1 1234Elzaelzevir

© 2022 - 2024 — McMap. All rights reserved.