Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does System.Net.Sockets.Socket() use its parameters?

When creating a new instance of this class, you specify a SocketType and ProtocolType. I want a SocketType of Stream. In the description of the Stream member, it says, "stream uses the TCP ProtocolType." However, I can still specify a different ProtocolType manually of UDP, ICMP, IGMP, ...

I'm not sure how this works at lower layers though - If I were to do something like...

new NetworkStream(new Socket(SocketType.Stream, ProtocolType.Icmp))

Would I be wrapping my stream in ICMP traffic (meaning stream data within ICMP headers)? Please provide as much information as possible so I might understand how this is actually working under the hood.

like image 874
Zee Avatar asked Aug 02 '26 10:08

Zee


1 Answers

The Socket constructor provides an explanation saying that "The combination of socketType and protocolType results in an invalid socket."

This means that nothing is done under the hood per se. It throws an exception and never makes it to the underlying winsock functions.

like image 187
Michael J. Gray Avatar answered Aug 04 '26 01:08

Michael J. Gray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!