title: Send TCP packet in C#
body: <p>I want to send a TCP packet (with a custom header) in C#. The building of such packets is no problem, and I have the data in a byte array. But how can I send this packet over a socket?</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP))
  {
      TcpPacket tcpPacket = new TcpPacket();
      // fill tcpPacket with data
      sock.Bind(new IPEndPoint(MYADDRESS, MYPORT));
      byte[] data = tcpPacket.GetBytes();
      sock.SendTo(data, new IPEndPoint(DESTADDRESS, DESTPORT));
  }
  </code></pre>
  
  <p>This runs without any exception but sniffing the network shows that nothing is send. What is the solution?</p>
  
  <p>I use Windows&nbsp;7 Professional, and I don't want the system to create the full TCP connection all alone.</p>
  
  <p>PS: I don't want to use some other library.  </p>
  
  <p>PS: Building IP packets is not a problem, either.</p>