问题描述
我用SOCKET接收文件,为什么会出现着错误:由于系统缓冲区空间不足或列队已满,不能执行套接字上的操作程序下,发送方:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Net.Sockets;usingSystem.IO;namespacesend{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}//发送privatevoidbutton1_Click(objectsender,EventArgse){Socketsocket=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);socket.Blocking=true;System.Net.IPEndPointipendpiont=newSystem.Net.IPEndPoint(System.Net.IPAddress.Parse("192.168.31.250"),8080);FileStreamfs=newFileStream(@"d:aa.txt",FileMode.OpenOrCreate,FileAccess.Read);byte[]bt=newbyte[fs.Length-1];BinaryReaderbr=newBinaryReader(fs);br.Read(bt,0,Convert.ToInt32(fs.Length)-1);socket.Connect(ipendpiont);//连接远程计算机socket.Send(bt);fs.Close();socket.Shutdown(SocketShutdown.Send);//'关闭发送连接socket.Close();//关闭本机socket}}}接收方:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Net.Sockets;usingSystem.IO;namespacerecv{publicpartialclassForm1:Form{Socketresocket=newSocket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){byte[]bb=newbyte[22988899000];Sockethostsock=resocket.Accept();//同意和发送端计算机建立连接hostsock.Receive(bb);if(hostsock.Receive(bb,bb.Length,0)>0.1){MessageBox.Show("yyyyy"+hostsock.Receive(bb));}FileStreamrefs=newFileStream(@"c:aa.txt",FileMode.OpenOrCreate);BinaryWriterbw=newBinaryWriter(refs);bw.Write(bb,0,bb.Length-1);refs.Close();hostsock.Shutdown(SocketShutdown.Receive);hostsock.Close();}privatevoidForm1_Load(objectsender,EventArgse){System.Net.IPEndPointhostip=newSystem.Net.IPEndPoint(System.Net.IPAddress.Parse("192.168.31.250"),8080);resocket.Bind(hostip);resocket.Listen(10000);}}}
解决方案
解决方案二:
在我的电脑--右键--属性--高级--性能--设置--高级--虚拟内存--更改--将“系统管理的大小”前面的小圆点选中,点确定就不会再出现你说的那种情况了!
解决方案三:
byte[]bb=newbyte[22988899000];//大约20G的内存空间啊?估计是这句出了为题,你问什么不循环接收呢??
解决方案四:
zzultc,怎么循环接收啊???
解决方案五:
你这个程序...........
解决方案六:
我这个程序是拷贝的,该怎么有用异步传输啊,各位谁做过,指点下
解决方案七:
beginreceiveendreceive和beginsendendsend来实现异步传输吧...