Why is my ReceivedBufferSize huge? Up to 65535 bytes










0















So I am playing around with the Tcp protocol in C# and figured I would connect to my server.
When I connect to my server it notifies me just fine. but then I go to check the ReceivedBufferSize and it's this receivedBuffer=byte[65536]



When in reality it only gives back a few bytes.



Why is this happening?
Sending this back to my client doesn't do anything either so I removed that part.
I figured it's because the packet is so big.



This part right here



byte receivedBuffer = new byte[client.ReceiveBufferSize];


returns receivedBuffer=byte[65536]



public partial class MainWindow : Window

public static IPAddress remoteAddress = IPAddress.Parse("127.0.0.1");
public TcpListener remoteServer = new TcpListener(remoteAddress, 7777);
public TcpClient client = default(TcpClient);

public MainWindow()

InitializeComponent();


private void BtnListen_OnClick(object sender, RoutedEventArgs e)

if (StartServer())

client = remoteServer.AcceptTcpClient();
MessageBox.Show("Connected");
byte receivedBuffer = new byte[client.ReceiveBufferSize];

NetworkStream clientStream = client.GetStream();

while (client.Connected)

if (client.Connected)

if (client.ReceiveBufferSize > 0)

receivedBuffer = new byte[100];
clientStream.Read(receivedBuffer, 0, receivedBuffer.Length);






private bool StartServer()

try

remoteServer.Start();
MessageBox.Show("Server Started...");
return true;

catch (Exception exception)

MessageBox.Show(exception.ToString());
throw;





As you can see here, it's only 15 bytes
enter image description here










share|improve this question
























  • Where are you seeing 65536? According to the docs, the default is 8 KiB

    – John
    Nov 15 '18 at 1:52












  • The byte receivedBuffer = new byte[client.ReceiveBufferSize]; contains that much, and I have no idea why it's so big

    – Mark Denom
    Nov 15 '18 at 1:53











  • If it is that big, why not create a smaller buffer?

    – John
    Nov 15 '18 at 1:53






  • 4





    The ReceiveBufferSize property is how many bytes you are expecting to receive in the buffer at a time, not the actual count of bytes received, if that's the confusion.

    – Jonathon Chase
    Nov 15 '18 at 1:54











  • Oh, okay! Yeah that makes sense then, I was curious to why there was so many empty bytes

    – Mark Denom
    Nov 15 '18 at 1:55















0















So I am playing around with the Tcp protocol in C# and figured I would connect to my server.
When I connect to my server it notifies me just fine. but then I go to check the ReceivedBufferSize and it's this receivedBuffer=byte[65536]



When in reality it only gives back a few bytes.



Why is this happening?
Sending this back to my client doesn't do anything either so I removed that part.
I figured it's because the packet is so big.



This part right here



byte receivedBuffer = new byte[client.ReceiveBufferSize];


returns receivedBuffer=byte[65536]



public partial class MainWindow : Window

public static IPAddress remoteAddress = IPAddress.Parse("127.0.0.1");
public TcpListener remoteServer = new TcpListener(remoteAddress, 7777);
public TcpClient client = default(TcpClient);

public MainWindow()

InitializeComponent();


private void BtnListen_OnClick(object sender, RoutedEventArgs e)

if (StartServer())

client = remoteServer.AcceptTcpClient();
MessageBox.Show("Connected");
byte receivedBuffer = new byte[client.ReceiveBufferSize];

NetworkStream clientStream = client.GetStream();

while (client.Connected)

if (client.Connected)

if (client.ReceiveBufferSize > 0)

receivedBuffer = new byte[100];
clientStream.Read(receivedBuffer, 0, receivedBuffer.Length);






private bool StartServer()

try

remoteServer.Start();
MessageBox.Show("Server Started...");
return true;

catch (Exception exception)

MessageBox.Show(exception.ToString());
throw;





As you can see here, it's only 15 bytes
enter image description here










share|improve this question
























  • Where are you seeing 65536? According to the docs, the default is 8 KiB

    – John
    Nov 15 '18 at 1:52












  • The byte receivedBuffer = new byte[client.ReceiveBufferSize]; contains that much, and I have no idea why it's so big

    – Mark Denom
    Nov 15 '18 at 1:53











  • If it is that big, why not create a smaller buffer?

    – John
    Nov 15 '18 at 1:53






  • 4





    The ReceiveBufferSize property is how many bytes you are expecting to receive in the buffer at a time, not the actual count of bytes received, if that's the confusion.

    – Jonathon Chase
    Nov 15 '18 at 1:54











  • Oh, okay! Yeah that makes sense then, I was curious to why there was so many empty bytes

    – Mark Denom
    Nov 15 '18 at 1:55













0












0








0








So I am playing around with the Tcp protocol in C# and figured I would connect to my server.
When I connect to my server it notifies me just fine. but then I go to check the ReceivedBufferSize and it's this receivedBuffer=byte[65536]



When in reality it only gives back a few bytes.



Why is this happening?
Sending this back to my client doesn't do anything either so I removed that part.
I figured it's because the packet is so big.



This part right here



byte receivedBuffer = new byte[client.ReceiveBufferSize];


returns receivedBuffer=byte[65536]



public partial class MainWindow : Window

public static IPAddress remoteAddress = IPAddress.Parse("127.0.0.1");
public TcpListener remoteServer = new TcpListener(remoteAddress, 7777);
public TcpClient client = default(TcpClient);

public MainWindow()

InitializeComponent();


private void BtnListen_OnClick(object sender, RoutedEventArgs e)

if (StartServer())

client = remoteServer.AcceptTcpClient();
MessageBox.Show("Connected");
byte receivedBuffer = new byte[client.ReceiveBufferSize];

NetworkStream clientStream = client.GetStream();

while (client.Connected)

if (client.Connected)

if (client.ReceiveBufferSize > 0)

receivedBuffer = new byte[100];
clientStream.Read(receivedBuffer, 0, receivedBuffer.Length);






private bool StartServer()

try

remoteServer.Start();
MessageBox.Show("Server Started...");
return true;

catch (Exception exception)

MessageBox.Show(exception.ToString());
throw;





As you can see here, it's only 15 bytes
enter image description here










share|improve this question
















So I am playing around with the Tcp protocol in C# and figured I would connect to my server.
When I connect to my server it notifies me just fine. but then I go to check the ReceivedBufferSize and it's this receivedBuffer=byte[65536]



When in reality it only gives back a few bytes.



Why is this happening?
Sending this back to my client doesn't do anything either so I removed that part.
I figured it's because the packet is so big.



This part right here



byte receivedBuffer = new byte[client.ReceiveBufferSize];


returns receivedBuffer=byte[65536]



public partial class MainWindow : Window

public static IPAddress remoteAddress = IPAddress.Parse("127.0.0.1");
public TcpListener remoteServer = new TcpListener(remoteAddress, 7777);
public TcpClient client = default(TcpClient);

public MainWindow()

InitializeComponent();


private void BtnListen_OnClick(object sender, RoutedEventArgs e)

if (StartServer())

client = remoteServer.AcceptTcpClient();
MessageBox.Show("Connected");
byte receivedBuffer = new byte[client.ReceiveBufferSize];

NetworkStream clientStream = client.GetStream();

while (client.Connected)

if (client.Connected)

if (client.ReceiveBufferSize > 0)

receivedBuffer = new byte[100];
clientStream.Read(receivedBuffer, 0, receivedBuffer.Length);






private bool StartServer()

try

remoteServer.Start();
MessageBox.Show("Server Started...");
return true;

catch (Exception exception)

MessageBox.Show(exception.ToString());
throw;





As you can see here, it's only 15 bytes
enter image description here







c# .net sockets tcp server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 1:53







Mark Denom

















asked Nov 15 '18 at 1:47









Mark DenomMark Denom

288110




288110












  • Where are you seeing 65536? According to the docs, the default is 8 KiB

    – John
    Nov 15 '18 at 1:52












  • The byte receivedBuffer = new byte[client.ReceiveBufferSize]; contains that much, and I have no idea why it's so big

    – Mark Denom
    Nov 15 '18 at 1:53











  • If it is that big, why not create a smaller buffer?

    – John
    Nov 15 '18 at 1:53






  • 4





    The ReceiveBufferSize property is how many bytes you are expecting to receive in the buffer at a time, not the actual count of bytes received, if that's the confusion.

    – Jonathon Chase
    Nov 15 '18 at 1:54











  • Oh, okay! Yeah that makes sense then, I was curious to why there was so many empty bytes

    – Mark Denom
    Nov 15 '18 at 1:55

















  • Where are you seeing 65536? According to the docs, the default is 8 KiB

    – John
    Nov 15 '18 at 1:52












  • The byte receivedBuffer = new byte[client.ReceiveBufferSize]; contains that much, and I have no idea why it's so big

    – Mark Denom
    Nov 15 '18 at 1:53











  • If it is that big, why not create a smaller buffer?

    – John
    Nov 15 '18 at 1:53






  • 4





    The ReceiveBufferSize property is how many bytes you are expecting to receive in the buffer at a time, not the actual count of bytes received, if that's the confusion.

    – Jonathon Chase
    Nov 15 '18 at 1:54











  • Oh, okay! Yeah that makes sense then, I was curious to why there was so many empty bytes

    – Mark Denom
    Nov 15 '18 at 1:55
















Where are you seeing 65536? According to the docs, the default is 8 KiB

– John
Nov 15 '18 at 1:52






Where are you seeing 65536? According to the docs, the default is 8 KiB

– John
Nov 15 '18 at 1:52














The byte receivedBuffer = new byte[client.ReceiveBufferSize]; contains that much, and I have no idea why it's so big

– Mark Denom
Nov 15 '18 at 1:53





The byte receivedBuffer = new byte[client.ReceiveBufferSize]; contains that much, and I have no idea why it's so big

– Mark Denom
Nov 15 '18 at 1:53













If it is that big, why not create a smaller buffer?

– John
Nov 15 '18 at 1:53





If it is that big, why not create a smaller buffer?

– John
Nov 15 '18 at 1:53




4




4





The ReceiveBufferSize property is how many bytes you are expecting to receive in the buffer at a time, not the actual count of bytes received, if that's the confusion.

– Jonathon Chase
Nov 15 '18 at 1:54





The ReceiveBufferSize property is how many bytes you are expecting to receive in the buffer at a time, not the actual count of bytes received, if that's the confusion.

– Jonathon Chase
Nov 15 '18 at 1:54













Oh, okay! Yeah that makes sense then, I was curious to why there was so many empty bytes

– Mark Denom
Nov 15 '18 at 1:55





Oh, okay! Yeah that makes sense then, I was curious to why there was so many empty bytes

– Mark Denom
Nov 15 '18 at 1:55












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311296%2fwhy-is-my-receivedbuffersize-huge-up-to-65535-bytes%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311296%2fwhy-is-my-receivedbuffersize-huge-up-to-65535-bytes%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線