Android真机如何访问PC上的tomcat

夏逝de風 2013-04-16 08:16:42
如题所述,在电脑上搭建了一个服务器,电脑是直接宽带连接,没用路由器,别人电脑可以通过我的IP访问到服务器,请问手机如何访问到服务器?(手机和电脑在同一局域网内时,是可以访问)
...全文
1373 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
cs张 2015-01-14
  • 打赏
  • 举报
回复
引用 12 楼 caiqiiqi 的回复:
哥们,,,可能只是电脑上的防火墙级别太高。 关掉防火墙就好了。我也郁闷了好久
搞了那么久才知道。是防火墙的问题。。
caiqiiqi 2015-01-10
  • 打赏
  • 举报
回复
哥们,,,可能只是电脑上的防火墙级别太高。
关掉防火墙就好了。我也郁闷了好久
ianafollow 2014-09-28
  • 打赏
  • 举报
回复
楼主,这该怎么做啊,我现在是模拟 器上能访问服务端,到手机上就不行。
kangming07 2013-04-18
  • 打赏
  • 举报
回复
引用 9 楼 qq329043840 的回复:
引用 8 楼 kangming07 的回复: 直接通过wifi来连接到自己的服务器端,把ip地址设置成自己的主机本地ip,端口号看自己tomcat设置多少 解决了,原来是端口的问题,不知道为什么学校的IP端口设成8080和80,手机就无法访问
默认端口号一般都是80,tomcat有时候默认的就是8080这个看自己的需求了,www网址的网站一般都是80端口可以自动隐藏,局域网一般自己设置自己的端口,自己访问比较方便
夏逝de風 2013-04-17
  • 打赏
  • 举报
回复
试过了,手机输入http://IP:8080/……访问不了~ 电脑可以 手机就是不行~
夏逝de風 2013-04-17
  • 打赏
  • 举报
回复
引用 8 楼 kangming07 的回复:
直接通过wifi来连接到自己的服务器端,把ip地址设置成自己的主机本地ip,端口号看自己tomcat设置多少
解决了,原来是端口的问题,不知道为什么学校的IP端口设成8080和80,手机就无法访问
kangming07 2013-04-17
  • 打赏
  • 举报
回复
直接通过wifi来连接到自己的服务器端,把ip地址设置成自己的主机本地ip,端口号看自己tomcat设置多少
kangming07 2013-04-17
  • 打赏
  • 举报
回复
我有源代码,发给你 public class TcpSocket { public static boolean ISCONNECT; static Socket socket; static OutputStream output; static InputStream input; private static String ip; private static int port; private Thread socThread = null; private byte[] readbuffer = null; /** * 创建客户端到服务器的连接Socket * * @param ip * @param port * @throws IOException */ public TcpSocket(String ip, int port) { TcpSocket.ip = ip; TcpSocket.port = port; } public boolean SocConnect() throws IOException { boolean re = true; if (socket == null) { try { InetAddress address = InetAddress.getByName(ip); socket = new Socket(address, port); TcpSocket.ISCONNECT = true; socThread = new Thread() { @Override public void run() { while (!isInterrupted()) { if (SocReceive().length > 0) { OnReceive.OnReceive(readbuffer); } } } }; } catch (ConnectException ce) { socket = null; // throw ce; re = false; } catch (IOException e) { SocClose(); // throw e; re = false; } } return re; } /** * 发送字节数组 * * @param bytes * @throws IOException */ public void SocSend(byte[] bytes) throws IOException { try { output = socket.getOutputStream(); output.write(bytes); output.flush(); // output.close(); } catch (IOException e) { SocClose(); throw e; } } /** * 接收字节数组并填充 * * @param bytes * @return * @throws IOException */ public byte[] SocReceive() { int len; byte[] readbuf = new byte[1024]; try { if (input.available() > 0) { len = input.available(); readbuffer = new byte[len]; int count = 0; while (count < readbuffer.length) { count += input.read(readbuffer, count, readbuffer.length - count); } return readbuffer; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return readbuffer; } public int receive(byte[] bytes) throws IOException { int rece = 0; try { input = socket.getInputStream(); rece = input.read(bytes); OnReceive.OnReceive(bytes); // input.close(); return rece; } catch (IOException e) { SocClose(); throw e; } } public void SocClose() throws IOException { try { if (output != null) output.close(); if (input != null) input.close(); if (socket != null) { socket.close(); socket = null; } TcpSocket.ISCONNECT = false; if (null != socThread) { socThread.stop(); socThread = null; } } catch (IOException e) { throw e; } } public SocOnReceiveDataHandleEvent OnReceive = null; public interface SocOnReceiveDataHandleEvent { public void OnReceive(byte[] bytes); } public SocOnReceiveDataHandleEvent getOnReceive() { return OnReceive; } public void setOnReceive(SocOnReceiveDataHandleEvent onReceive) { OnReceive = onReceive; } }
夏逝de風 2013-04-17
  • 打赏
  • 举报
回复
引用 5 楼 longer262110 的回复:
引用 4 楼 qq329043840 的回复:试过了,手机输入http://IP:8080/……访问不了~ 电脑可以 手机就是不行~ 你的手机可以上公网吗?
上公网? 手机上网有什么不一样的么?
longer262110 2013-04-17
  • 打赏
  • 举报
回复
引用 4 楼 qq329043840 的回复:
试过了,手机输入http://IP:8080/……访问不了~ 电脑可以 手机就是不行~
你的手机可以上公网吗?
麦田捕手 2013-04-16
  • 打赏
  • 举报
回复
很简单,通过wifi,手机连wifi,电脑也连上wifi,这时根据ip及端口就可访问了
L2665149919 2013-04-16
  • 打赏
  • 举报
回复
通过你的ip访问
wlcw16 2013-04-16
  • 打赏
  • 举报
回复
通过你的ip访问啊。 电脑能访问手机就可以啊。

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧