解决方案 »

  1.   

    很简单,通过wifi,手机连wifi,电脑也连上wifi,这时根据ip及端口就可访问了
      

  2.   

    试过了,手机输入http://IP:8080/……访问不了~  电脑可以 手机就是不行~
      

  3.   

    我有源代码,发给你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;
    }}
      

  4.   

    直接通过wifi来连接到自己的服务器端,把ip地址设置成自己的主机本地ip,端口号看自己tomcat设置多少
      

  5.   

    默认端口号一般都是80,tomcat有时候默认的就是8080这个看自己的需求了,www网址的网站一般都是80端口可以自动隐藏,局域网一般自己设置自己的端口,自己访问比较方便