none
Send packet hex data to tcp server RRS feed

  • Question

  • Hi everyone!,

    I'm trying to send a packet that contain a specific hex data, to a tcp listener (127.0.0.1 for me),
    So after reading the example here, almost perfect except a few things,
    1- it connects to the tcp server, send the packet and instantly close it, I can't send more than one packet without reconnecting.
    2- sending the packet as hex, do I need to store the hex as byte array?, I want the packet to contain specific hex value "C2 F6 8B..etc".

    how can I achieve this please?
    Thanks in advance.

    Wednesday, March 21, 2018 7:28 AM

All replies

  • Who is closing the connection?  If it's your code, then the obvious answer is "don't close the connection until you're through with it".  ;)  If the other end is closing the connection, it may be that you have sent it garbage data.

    The phrase "specific hex data" is confusing, because it can man different things.  Hex is just a convenience for humans.  If you want raw binary data, which is likely, then you can do:

    Byte[] data = new Byte[128];
    data[0] = 0xC2;
    data[1] = 0xF6;
    data[2] = 0x8B;
    // or
    Byte[] data = new Byte[]{ 0xc2, 0xf6, 0x8b };

    Some people think of hex data as meaning "human readable ASCII characters", like the literal string "C2 F6 8B".  You'd want that if you intend to display the string for humans, but that's almost never what computer-to-computer communications want.


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Wednesday, March 21, 2018 6:22 PM