2

I want to change udpclient receivebuffersize in order to prevent buffer overflow when receiving udp packets. is it possible to change it in c#. The actual property is UdpClient.Client.ReceiveBufferSize. Do i have to use other method?

Thanks.

Syaiful Nizam Yahya
  • 4,196
  • 11
  • 51
  • 71
  • Did you make sure to [set `ReceiveBufferSize` directly after creating the `UdpClient`](http://stackoverflow.com/a/9680672/709537), before doing anything with it? – Evgeniy Berezovsky Feb 03 '15 at 04:16

2 Answers2

2

You should be able to doing the following:

  UdpClient client = new UdpClient();
  client.Client.ReceiveBufferSize = 4096;
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
  • I think i did mention that i am aware of UdpClient.Client.ReceiveBufferSize. From http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.receivebuffersize.aspx, ReceiveBufferSize is used only for tcpclient. I did test in my udpclient but sees no difference. actually, i veeeery sure it doesnt work for udp. thats why i asked here. – Syaiful Nizam Yahya Nov 12 '10 at 20:17
  • Others have gotten this to work, check out this post: http://stackoverflow.com/questions/2408212/how-can-i-set-the-buffer-size-for-the-underneath-socket-udp-c – SwDevMan81 Nov 12 '10 at 20:37
0

I don't know whether this helps, but it looks like UdpClient allows you to provide your own Socket. Internally, UdpClient creates the Socket with this statement:

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

In the Connect(), it checks whether Client has already been set and, if so, uses that Socket to connect to.

Pieter van Ginkel
  • 29,160
  • 8
  • 71
  • 111