Search code examples
linuxtcptelnetnetcat

How can I send a byte (or bytes) to test a socket listening in my application?


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?


Solution

  • 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