Sunday, March 2, 2014

android udp really rubbish ah or I write rubbish.


wince apple send udp packet loss rate is almost zero in the LAN China. Performance is quite good. In the android dropout rate of around 10%. Is really a headache. Code is as follows:

public UdpClientSocket () {

this.host = "255.255.255.255" ;/ / change target IP, instead of broadcasting the effect is not obvious.

try {
ds = new DatagramSocket ();


} Catch (SocketException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
/ / This.host = host;
}



public void send (byte [] bytes) {

DatagramPacket dp;
try {ds.setSendBufferSize (1) ;/ / this with and without the effect is not obvious.
dp = new DatagramPacket (bytes, bytes.length,
InetAddress.getByName (this.host), 1024);
ds.send (dp);

} Catch (UnknownHostException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
} Catch (IOException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}



}

Where do bad, it is to throw so many packages that I have tested on multiple android too, have the same problem.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
UDP itself does not guarantee the integrity of data transmission, on a handshake. The landlord can try three-way handshake TCP.
Reply:
UDP does not very reliable, he does not guarantee the success of communication, the transmission speed is faster than TCP. Why do you not TCP.
Reply:
tcp, then it is inconvenient to know each other's IP, to reconnection. There will be many problems.
If you click the button
TCP connection, send buf, then disconnect the real-time is not very good.
If long connection, writing is also a hassle.

Reply:
Depend on the network. If the network is relatively poor, TCP will not connect on. Udp network is good also, after I added a validation mechanism in the network a better place, the situation is quite optimistic.
Reply:
Landlord, I also do Andrews LAN test, broadcasting, then Android phones loss is indeed serious, always lost 5%, and with the level of mobile phone hardware, good phone, mobile phone less strong performance loss, almost cell phone, lost package, the more you now that udp packet loss problem is how to solve it? later?

No comments:

Post a Comment