Syaiful Nizam Yahya
Syaiful Nizam Yahya

Reputation: 4305

Is it possible to set UdpClient ReceiveBufferSize property in c#?

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.

Upvotes: 2

Views: 3383

Answers (2)

Pieter van Ginkel
Pieter van Ginkel

Reputation: 29632

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.

Upvotes: 0

SwDevMan81
SwDevMan81

Reputation: 49978

You should be able to doing the following:

  UdpClient client = new UdpClient();
  client.Client.ReceiveBufferSize = 4096;

Upvotes: 2

Related Questions