TcpClient缓冲区大小限制? [英] TcpClient buffer size limit?
问题描述
我正在使用TcpClient并通过以下方式获取Stream:
TcpClient tcpclnt = new TcpClient();
。 。 。
流stm = tcpclnt.GetStream();
现在,当我试图通过stm.Write发送一个大缓冲区时(... 。)我得到一个
异常,说缓冲区太大。
我试图将tcpclnt.ReceiveBufferSize设置为缓冲区I的大小。 m
试图发送,但异常仍然被抛出,没有传输
缓冲区我可以设置。
如何我可以解决这个问题,除了分割我的缓冲区并通过
块发送它吗?
缓冲区的限制是什么?
-
谢谢
Sharon G.
I''m using TcpClient and getting the Stream by:
TcpClient tcpclnt = new TcpClient();
. . .
Stream stm = tcpclnt.GetStream();
Now, when I''m trying to send a big buffer via stm.Write(...) I get an
exception saying that the buffer is too big.
I tried to set the tcpclnt.ReceiveBufferSize to the size of the buffer I"m
trying to send, but the exception is still thrown, there is no transmit
buffer I can set.
How can I solve this problem beside splitting my buffer and transmit it by
chunks?
What is the limit of the buffer?
--
Thanks
Sharon G.
推荐答案
hi sharon,
奇怪的错误,您可以发布代码部分吗?
写入不需要创建新的缓冲区,它已经创建了。
>
欢呼,
-
Ignacio Machin,
ignacio.machin at dot.state.fl。我们
佛罗里达州交通局
" Sharon" <嘘**** @ discussions.microsoft.com>在消息中写道
新闻:0E ********************************** @ microsof t.com ...
hi sharon,
weird error, could you post the code section ?
Write do not need to create a new buffer, it;s already created.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Sharon" <Sh****@discussions.microsoft.com> wrote in message
news:0E**********************************@microsof t.com...
我正在使用TcpClient并获取Stream:
TcpClient tcpclnt = new TcpClient();
。 。 。
Stream stm = tcpclnt.GetStream();
现在,当我试图通过stm.Write(...)发送一个大缓冲区时,我得到一个
异常说缓冲区太大。
我试图将tcpclnt.ReceiveBufferSize设置为我试图发送的缓冲区的大小,但仍然抛出异常,没有我可以设置的传输缓冲区。
如何解决这个问题除了拆分我的缓冲区并通过
块传输它?
有什么限制缓冲区?
- 谢谢
Sharon G。
I''m using TcpClient and getting the Stream by:
TcpClient tcpclnt = new TcpClient();
. . .
Stream stm = tcpclnt.GetStream();
Now, when I''m trying to send a big buffer via stm.Write(...) I get an
exception saying that the buffer is too big.
I tried to set the tcpclnt.ReceiveBufferSize to the size of the buffer I"m
trying to send, but the exception is still thrown, there is no transmit
buffer I can set.
How can I solve this problem beside splitting my buffer and transmit it by
chunks?
What is the limit of the buffer?
--
Thanks
Sharon G.
好的,这是代码:
//////////////////
//客户:
//////////////////
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect(" ip address",8001);
byte [] rowData = new byte [104857600]; // 100 MByte
tcpclnt.ReceiveBufferSize = rowData.Length;
Stream stm = tcpclnt.GetStream();
stm.Write(rowData,0,rowData.Length); //抛出一个EXCEPTION !!!
//收到Ack。
ack =新字节[100];
k = stm.Read( ack,0,ack.Length);
tcpclnt.Close();
/////////////// ///
// Serevr:
//////////////////
ASCIIEncoding encoding = new ASCIIEncoding();
IPAddress ipAd = IPAddress.Parse(" ip address"); //与
客户端使用的IP地址相同。 />
TcpListener myList = new TcpListener(ipAd,8001);
myList.Start();
Socket sock = myList.AcceptSocket();
byte [] rowData = new byte [104857600]; // 100 MByte
recLen = sock.Receive(rowData); //抛出一个EXCEPTION !!!
sock.Close();
myList.Stop();
////// /////////////////////
有什么想法吗?
------ -
谢谢
Sharon
OK, here is the code:
//////////////////
// The client:
//////////////////
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect("ip address", 8001);
byte [] rowData = new byte[104857600];// 100 MByte
tcpclnt.ReceiveBufferSize = rowData.Length;
Stream stm = tcpclnt.GetStream();
stm.Write(rowData, 0, rowData.Length); // throwing an EXCEPTION !!!
// Receiving Ack.
ack = new byte[100];
k = stm.Read(ack, 0, ack.Length);
tcpclnt.Close();
//////////////////
// The Serevr:
//////////////////
ASCIIEncoding encoding = new ASCIIEncoding();
IPAddress ipAd = IPAddress.Parse("ip address");// Same IP address as the
clients uses.
TcpListener myList = new TcpListener(ipAd, 8001);
myList.Start();
Socket sock = myList.AcceptSocket();
byte [] rowData = new byte[104857600];// 100 MByte
recLen = sock.Receive(rowData); // throwing an EXCEPTION !!!
sock.Close();
myList.Stop();
///////////////////////////
Any idea ?
--------
Thanks
Sharon
hi sharon
我得到了同样的错误,这是我第一次看到它,你有多少内存呢?
?我只有512并且当我创建两个
缓冲区时我报告了大约800个但是在发送之前,可能缓冲区太大了,我认为你这个b $ b应该做一个谷歌搜索,看看是否有人之前有这个错误
抱歉无法为你提供进一步的帮助:(
欢呼,
>
-
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
佛罗里达州交通局
" Sharon" Sh **** @ discussion.microsoft.com>写在留言中
news:79 *********** *********************** @ microsof t.com ...
hi sharon
I got the same error, this is the first time I see it, how many memory do
you have? I only have 512 and I got reported around 800 when I create both
buffers but before send it, maybe the buffer is too big, I think that you
should do a google search to see if anybody has got this error before
Sorry not be able to help you further :(
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Sharon" <Sh****@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
好的,这是代码:
//////////////////
//客户:
/////////////// ///
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect(" ip address",8001);
byte [] rowData = new byte [104857600]; // 100 MByte
tcpclnt.ReceiveBufferSize = rowData.Length;
Stream stm = tcpclnt.GetStream();
stm.Writ e(rowData,0,rowData.Length); //抛出一个异常!!!
//接收Ack。
ack =新字节[100];
k = stm.Read(ack,0,ack.Length);
tcpclnt.Close();
//////////////////
// Serevr:
/// ///////////////
ASCIIEncoding encoding = new ASCIIEncoding();
IPAddress ipAd = IPAddress.Parse(" ip address"); //相同的IP地址正如
客户端使用的那样。
TcpListener myList = new TcpListener(ipAd,8001);
myList.Start();
Socket sock = myList.AcceptSocket();
byte [] rowData = new byte [104857600]; // 100 MByte
recLen = sock.Receive(rowData); //抛出一个EXCEPTION !!!
sock.Close();
myList.Stop();
////////////////// /////////
任何想法?
--------
谢谢
Sharon
OK, here is the code:
//////////////////
// The client:
//////////////////
TcpClient tcpclnt = new TcpClient();
tcpclnt.Connect("ip address", 8001);
byte [] rowData = new byte[104857600];// 100 MByte
tcpclnt.ReceiveBufferSize = rowData.Length;
Stream stm = tcpclnt.GetStream();
stm.Write(rowData, 0, rowData.Length); // throwing an EXCEPTION !!!
// Receiving Ack.
ack = new byte[100];
k = stm.Read(ack, 0, ack.Length);
tcpclnt.Close();
//////////////////
// The Serevr:
//////////////////
ASCIIEncoding encoding = new ASCIIEncoding();
IPAddress ipAd = IPAddress.Parse("ip address");// Same IP address as the
clients uses.
TcpListener myList = new TcpListener(ipAd, 8001);
myList.Start();
Socket sock = myList.AcceptSocket();
byte [] rowData = new byte[104857600];// 100 MByte
recLen = sock.Receive(rowData); // throwing an EXCEPTION !!!
sock.Close();
myList.Stop();
///////////////////////////
Any idea ?
--------
Thanks
Sharon
这篇关于TcpClient缓冲区大小限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!