开发者

Communicating between Android phone and PC using TCP in java

I'm working on a project where I want my Droid 2 to be able to send and receive data over 3G, to a device connected to an ethernet port (not necessarily a PC, but I'm using this for testing the communication). I believe that eventually the end to end communication will be accomplished over an SSL tunnel开发者_StackOverflow中文版, but for right now, I just need to establish basic communication to show that the devices can communicate.

I've written some client/server applications that worked between two computers on the same network, but I'm not sure if the communication in this case will work because of the different networks that the phone and PC are on.

I've been trying to establish if this can be done by pinging some of the PCs at my University and house using a pinging program I got off the market, but I've had no success so far. However, my friend has rooted his phone, and was able to do so.

I suppose this question really has two parts: 1) Is this possible? and 2) Do I need to root my phone to accomplish this, or should I be able to do it without rooting?

Thanks for any responses.


I've never worked with Android phones but I think:

  1. You do not need to have a root access to use sockets;
  2. You said that you want to use 3G to connect to your home PC and I suppose you have some kind of router at home and you need to configure port mapping from your router to your desktop.


I've written some client/server applications that worked between two computers on the same network, but I'm not sure if the communication in this case will work because of the different networks that the phone and PC are on.

One potential problem I can see is that, depending on your 3G provider, there may be a restriction on port numbers and protocols that can be used. For instance, HTTP to any port number may be allowed but unknown packet data (i.e., an unidentifiable protocol) to the same port numbers that work for HTTP, may be dropped.

I've been trying to establish if this can be done by pinging some of the PCs at my University and house using a pinging program I got off the market, but I've had no success so far. However, my friend has rooted his phone, and was able to do so.

Again, another potential problem - ping (ICMP) is not a good test of accessing devices on other networks as most perimeter routers/firewalls will by default refuse ICMP traffic (usually silently) - even my home DSL router/firewall silently blocks ICMP by default. As for needing a rooted phone to be allowed to use a ping app - my phone isn't rooted and I have a ping app from the market which works fine.

I suppose this question really has two parts: 1) Is this possible? and 2) Do I need to root my phone to accomplish this, or should I be able to do it without rooting?

There is no reason I know of that would require a phone to be rooted to use socket-based comms, I'm just wondering if trying to ping across a router/firewall isn't the best test for what you are trying to achieve.

I'd recommend starting with HTTP - I don't know what you use to program for the PC but a simple HTTP 'listener' should be easy enough to put together. Start by listening on port 80 and try from the Android browser - if that works, change the listening port to something like 6789 (remember to open the ports on your home router/firewall). Assuming you've got that working, try using the socket-based stuff you've developed using wi-fi on your LAN, if that works, then try over 3G.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜