1

I am attempting to interop with a custom hardware device.

It requires the first TCP packet to contain a data payload

I tried to achieve this using TcpClient in System.Net.Sockets

   TcpClient tcpclnt = new TcpClient();
   tcpclnt.Connect("192.168.1.11", 1500);
   Stream stm = tcpclnt.GetStream();
   byte[] ba = messagestr.StringToByteArray();                   
   stm.Write(ba, 0, ba.Length);

However wireshark shows that this code sends a number of TCP/IP packets to establish a connection and the data packet (containing messagestr) is the 4-5th packet.

How can I make C# send the data in the FIRST TCP packet?

7
  • If you don't want TCP to establish a connection, are you sure that your requirement is to create a TCP socket? Don't you need a raw socket? Commented Oct 2, 2015 at 13:30
  • wiresharking the correct packets I am trying to imitate shows them to be well formed TCP packets (though just 1 sent / 1 received) Commented Oct 2, 2015 at 13:32
  • 1
    If that really is the protocol that the hardware device implements, I suspect the creators to have been high on something. How does the SYN/ACK/sequence flow work then? Anyway check TCP/IP Raw Sockets, How do you get raw TCP packet in C#?, Send TCP packet in C#. Commented Oct 2, 2015 at 13:33
  • "I suspect the creators to have been high on something" yes I fully agree(!) this is a RS232 protocol embedded into TCP packets :( Commented Oct 2, 2015 at 13:37
  • 1
    If you want to send hand-crafted TCP packets you need to use the WinPcap library. There are Pcap wrappers for C# like SharpPcap available. Commented Oct 2, 2015 at 14:00

1 Answer 1

3

Use UDP to send only one packed without establishing a session. You are literally asking TCP not to be TCP.

Sign up to request clarification or add additional context in comments.

1 Comment

wiresharking the correct packets I am trying to imitate shows them to be well formed TCP packets (though just 1 sent / 1 received) ... should I therefore be trying to create a TCP packet using the UDP protocol?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.