gpt4 book ai didi

c# - C#-NetworkStream错误- “The operation is not allowed on non-stream oriented sockets.”

转载 作者:行者123 更新时间:2023-12-03 12:01:28 27 4
gpt4 key购买 nike

我正在尝试连接到套接字,然后读取NetworkStream。

我的代码如下:

NetworkStream myNetworkStream;
Socket socket;

socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IPv4);

socket.Connect(IPAddress.Parse("8.8.8.8"), 8888);

myNetworkStream = new NetworkStream(socket);

byte[] buffer = new byte[1024];
int offset = 0;
int count = 1024;

myNetworkStream.Read(buffer, offset, count);

当我尝试调试以上内容时,出现以下错误:

The operation is not allowed on non-stream oriented sockets.



我究竟做错了什么?

谢谢

最佳答案

您需要使用SocketType.Stream代替SocketType.Raw

关于c# - C#-NetworkStream错误- “The operation is not allowed on non-stream oriented sockets.”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8095476/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com