sockets - C# BeginReceiveFrom is giving me an error -
i need program listen several machines send out udp on status. cut , pasted bits chat program , got things working on startup error "an operation on socket not performed because system lacked sufficient buffer space or because queue full". if ok error works well. in code below if remove while(true) not error 1 entry. thought may wrong callback keep running , everytime gets data send dealt with. believe problem cannot work out how fix how keep receiving data without polling socket?
private void form1_load(object sender, eventargs e) { try { checkforillegalcrossthreadcalls = false; //we using udp sockets serversocket = new socket(addressfamily.internetwork, sockettype.dgram, protocoltype.udp); //assign ip of machine , listen on port number 701 ipendpoint ipendpoint = new ipendpoint(ipaddress.any, 701); //bind address server serversocket.bind(ipendpoint); ipendpoint ipesender = new ipendpoint(ipaddress.any, 0); //the epsender identifies incoming clients endpoint epsender = (endpoint)ipesender; while (true) { //start receiving data serversocket.beginreceivefrom(bytedata, 0, bytedata.length, socketflags.none, ref epsender, new asynccallback(onreceive), epsender); } } catch (exception ex) { messagebox.show(ex.message, "sgsserverudp", messageboxbuttons.ok, messageboxicon.error); } }
don't put beginreceivefrom
in loop. put itself. need put beginreceivefrom
inside onreceive
function , grab next set of data.
Comments
Post a Comment