c++ - UDP packet loss differs on package size -



c++ - UDP packet loss differs on package size -

i have application test udp sockets in qt. simple. 1 socket binds port , listens incomming packages. other socket used send packages. first number in bundle packages sent sender, subsequent info test. when receiver gets bundle shows received/sent rate. can vary bundle size, , timeout of timer send packages. , have 2 computers behind 2 different routers, tested this:

bind both sockets same port. add together port forwarding port. send packets 127.0.0.1 , router external ip.

both computers showed, maximum size of bundle received 32kb - 28b. 28b udp header size. suppose.

then seek test in same way between 2 computers. , test shows same results in 1 way(for illustration when send comp1 comp2), when send comp2 comp1 maximum size around 3kb(2975b). comp1 not bundle larger this.

this code of program:

mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow), receivesocket(), sendsocket(), timer(), packetsend(0), packetreceived(0), address(), sendport(63465), receiveport(62345), { ui->setupui(this); timer.setsingleshot(false); timer.setinterval(100); receivesocket.bind(receiveport); connect(&timer, signal(timeout()), this, slot(senddata())); connect(&receivesocket, signal(readyread()), this, slot(receivedata())); connect(ui->startbutton, signal(clicked()), this, slot(startstopsend())); } mainwindow::~mainwindow() { delete ui; } void mainwindow::receivedata() { unsigned int othersidesent = 0; { receivedatagram.resize(receivesocket.pendingdatagramsize()); receivesocket.readdatagram(receivedatagram.data(), receivedatagram.size()); }while(receivesocket.haspendingdatagrams()); qdatastream in(&receivedatagram, qiodevice::readonly); in >> othersidesent; float tempval; std::vector<float> value; (int i=0; i<receivedatagram.size()/8 - 1;i++ ) { in >> tempval; value.push_back(tempval); } packetreceived++; ui->packetdata->settext(qstring("i receive/you sent: ")+qstring::number(packetreceived)+qstring("/")+qstring::number(othersidesent)); } void mainwindow::senddata() { qdatastream out(&senddatagram, qiodevice::writeonly); out << ++packetsend; for(unsigned int = 0; < 8185; ++i) { out << 1.0 + i/100.0; } sendsocket.writedatagram(senddatagram, address, sendport); } void mainwindow::startstopsend() { if(!timer.isactive()) { address.setaddress(ui->ipline->text()); timer.start(); } else { timer.stop(); } }

first test, think, showed none router1, router2, comp1 or comp2 limits maximum size of udp package. in case comp2 comp1 maximum bundle size limited unusual number.

question why?

most devices back upwards mtu/mru around 1500 bytes. fact can send/receive packets larger means either have jumbo frames enabled way through, or packets getting fragmented.

it isn't 100% clear doing, mentioned router external ip. if 2 computers sitting on 2 different locations connected net via 2 different routers, oversized packets sending fragmented routers "connect internet".

i think it's amazing can send 32kb packet comp1 comp2 via internet, if that's doing, because router has firstly fragment won't happy when receives 32kb sized packet , have fragment downwards to, say, 32 x 1kb packets, not mention receiving end, have reassemble it.

i not sure trying test when 'to test udp sockets', network tests performed packets sizes less 1518 (or 1522) bytes reason.

c++ qt sockets networking

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -