I have tried many tests on how to create a UDP server on android phone. - Devices I was testing:
PC (has static public IP over Internet. has a UDP server running) GPhone (it is real phone, not emulator. runs in Tmobile 3G network) - Send a UDP packet from GPhone to PC: [On GPhone:] // create a sender socket DatagramSocket udpClientSocket= new DatagramSocket(); // send data udpClientSocket.send(packet); [On PC:] // create a listener socket DatagramSocket udpServerSocket = new DatagramSocket(SERVER_PORT); // receive data udpServerSocket.receive(packet); - Send a UDP packet from PC to GPhone After a whole day testing on this problem, I can only find this solution: [On PC:] // get the client's address and port address = packet.getAddress(); port = packet.getPort(); // create packet to send to client packet = new DatagramPacket(....address, port); // use the server socket to send a packet udpServerSocket.send(packet); [On GPhone:] // use the sender socket to receive data udpClientSocket.receive(packet); With these codes, the client can actually receive packet from server. However, there are 2 problems: 1. YOU HAVE TO USE THE SERVER SOCKET TO SEND If we change the PC code to: .....(same stuff) // create a new socket to send data DatagramSocket anotherSocket = new DatagramSocket(); anotherSocket.send(packet); The phone will never receive the packet. 2. YOU CANNOT ESTABLISH A UDP SERVER ON GPHONE If we want to have a UDP server on GPhone just like we have a server on PC. So that GPhone can talk to a server on PC and PC can talk to another server on GPhone, using DatagramSocket udpGPhoneServerSocket = new DatagramSocket(GPHONE_SERVER_PORT) DOES NOT WORK. I have tried to send a UDP packet from PC to the phone. I tried all kinds of ports, addresses, etc. No, it doesn't work. * * * * * * * * * * * * * * * * * * * * * * * * OK. Now in my android app, I have over 100 clients (GPhone) communicating to the server (PC) at same time. For performance concern, I want to create one UDP server socket on PC *ONLY* for receiving. Then I create one UDP sending socket per connection on the server to send packets back to the phone. Based on my test, since establishing a UDP server socket on GPhone is not working. The only option left for me is to use the only UDP server socket for both receiving and sending. My questions are: 1. Am I wrong? (Does any1 have a successful design so that you can send a packet from PC to GPhone without reusing the server socket?) 2. If I am correct, is it T-mobile blocking all UDPs? 3. If I use the *ONLY* server socket for both sending and receiving to handle 100+ connections with real-time data exchanging at same time, does it have a poor performance? Any better solutions? Any comments are appreciated! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en