簡體   English   中英

C#UDP sendto緩沖區

[英]C# UDP sendto buffer

我正在制作一個將發送1MB長度數據的應用程序。 Bellow是我的測試代碼,它只是發送一個1MB的簡單字節數組,但是即使我嘗試將發送緩沖區增加到1MB或更高,它仍然會拋出波紋管異常。

private void sendattack(string ip, int port)
    {
        IPEndPoint RemoteEndPoint = new IPEndPoint(IPAddress.Parse(ip), port);
        Socket serversoc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        char[] data = new char[100000];
        var send = Encoding.ASCII.GetBytes(data);
        serversoc.SendTo(send, send.Length, SocketFlags.None, RemoteEndPoint);
    }

錯誤

在數據報套接字上發送的消息大於內部消息緩沖區或某些其他網絡限制,或者用於接收數據報的緩沖區小於數據報本身

System.Net.Sockets.SocketException未處理ErrorCode = 10040 HResult = -2147467259消息=在數據報套接字上發送的消息大於內部消息緩沖區或某些其他網絡限制,或者用於接收數據報的緩沖區小於數據報本身NativeErrorCode = 10040 Source = System StackTrace:在System.Net.Sockets.Socket.SendTo的System.Net.Sockets.Socket.SendTo(Byte []緩沖區,Int32偏移量,Int32大小,SocketFlags socketFlags,EndPoint remoteEP)處(字節[]緩沖區,Int32大小,SocketFlags socketFlags,EndPoint remoteEP)位於C:\\ Users \\ User \\ OneDrive \\ Documents \\ Visual Studio 2013 \\ Projects \\ qnet \\ qnet \\ svchost中的qnet.svchost.sendattack(String ip,Int32 port) .cs:第84行,位於C:\\ Users \\ User \\ OneDrive \\ Documents \\ Visual Studio 2013 \\ Projects \\ qnet \\ qnet \\ svchost.cs中的qnet.svchost.Form1_Load(Object sender,EventArgs e):System.Windows第27行System.Windows.Forms.Control.CreateControl(Boolea)上System.Windows.Forms.Form.OnCreateControl()的.Forms.Form.OnLoad(EventArgs e) System.Windows.Forms.Forms.Forms.Forms.Forms.Ot。在System.Windows.Forms.Conm.WreS的一個系統中,System.Windows.Forms.Conm.WandSroc上的System.Windows.Forms.Conm.WmShowWindow(Message&m)處的System.Windows.Forms.Control.CreateControl(。) ScrollableControl.WndProc(Message&m)在System.Windows.Forms.Form.WndShowWindow上的System.Windows.Forms.Form.WmShowWindow(Message&m),在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)的System.Windows.Forms.Form.WndProc(Message&m) )System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)InnerException:

錯誤是不言自明的:您不能發送大的數據包。 UDP數據包的理論最大大小約為64KB,通過互聯網安全發送而沒有分片的大小小於1KB: Internet上最大的安全UDP數據包大小是多少

你需要把事情做得更小。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM