Send TCP packet in C#

后端 未结 6 1139
栀梦
栀梦 2020-12-17 06:55

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 ove

6条回答
  •  感动是毒
    2020-12-17 07:19

    You should use SocketType.Stream:

    SocketType.Raw: Supports access to the underlying transport protocol. Using the SocketTypeRaw, you can communicate using protocols like Internet Control Message Protocol (Icmp) and Internet Group Management Protocol (Igmp). Your application must provide a complete IP header when sending. Received datagrams return with the IP header and options intact.

    SocketType.Stream: Supports reliable, two-way, connection-based byte streams without the duplication of data and without preservation of boundaries. A Socket of this type communicates with a single peer and requires a remote host connection before communication can begin. Stream uses the Transmission Control Protocol (Tcp) ProtocolType and the InterNetworkAddressFamily.

提交回复
热议问题