实例化TCP套接字的正确参数是什么?

时间:2013-11-18 02:22:43

标签: c# sockets tcp

我需要创建一个Socket类的实例,但我不确定我应该解析什么参数来创建TCP套接字,

    System.Net .Sockets .Socket s = new System.Net.Sockets.Socket
 (//what are the parameters required in here ?") 

1 个答案:

答案 0 :(得分:2)

对于tcp:

Socket s = new Socket(AddressFamily.InterNetwork, 
   SocketType.Stream, ProtocolType.Tcp);

对于Udp:

Socket s = new Socket(AddressFamily.InterNetwork, 
   SocketType.Dgram, ProtocolType.Udp);

上面的代码示例显示您必须以任何方式实例化套接字