【问题标题】:socket connection works well in wireless toolkit but no in my nokia phone套接字连接在无线工具包中运行良好,但在我的诺基亚手机中没有
【发布时间】:2013-03-11 14:57:54
【问题描述】:
    wireless toolkit code

//客户端移动的j2me代码

    public class TCPConnectSend extends MIDlet implements CommandListener {
    Display display;

    public TCPConnectSend0 () {
    frm = new Form ("TCPConnectSend0");
    sendCmd = new Command("Send",Command.SCREEN, 1);
    frm.addCommand(sendCmd);
    frm.setCommandListener(this);
    text = new TextField("text:","",40,TextField.ANY);
    frm.append(text);
    }
    public void startApp() {
    if(display==null) {
    display = Display.getDisplay (this);
    }
    display.setCurrent(frm);
    try {
    conn=(SocketConnection)Connector.open("socket://|ip-address|:80");//socket connection to the server

    outs=conn.openOutputStream();
    } catch(IOException e) { }
    }
    public void pauseApp() { }
    public void destroyApp(boolean unconditional) { }
    public void commandAction(Command c, Displayable s) {
    if(c==sendCmd) {
    try {
    outs.write((text.getString()+"\n").getBytes());
    } catch(IOException e) {}
    } else { }
    }
    }

    server code

//这接收来自客户端的套接字请求

    class TCPServer
    {
       public static void main(String argv[]) throws Exception
          {
             try {
                ServerSocket server = new ServerSocket(80);
        System.out.println("ip address : "+InetAddress.getLocalHost());         
        System.out.println("waiting for connection");               
        Socket s1 = server.accept();
        System.out.println("connection established");
        BufferedReader br = new BufferedReader(new
InputStreamReader(s1.getInputStream()));    
            while (true) {
                String str1 = br.readLine();
            System.out.println("client says :" +str1);              
                if (str1.equals("quit"))
                        break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
          }
    }

//运行此代码后,我在诺基亚手机中遇到 java 安全异常,任何其他端口号在诺基亚手机中都没有响应

【问题讨论】:

    标签: sockets java-me nokia


    【解决方案1】:

    问题的发生是因为诺基亚为其某些系统应用程序阻止了 80 端口号,因此更改端口号以及公共 IP 地址就可以解决问题

    【讨论】:

      【解决方案2】:

      您应该在客户端代码中添加服务器的公共 IP。

      (SocketConnection)Connection.open( "socket://105.225.251.58" + ":" + "port" );
      

      【讨论】:

        【解决方案3】:

        请注意,要使用 80、443、8080 等特权端口以及通常低于 1000 的任何端口,您需要一个真实手机的代码签名证书(例如来自 Thawte)。

        否则,仍然使用更高的非特权端口,例如 8000 等

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-10-20
          • 1970-01-01
          • 2018-12-13
          • 1970-01-01
          • 2013-02-12
          • 2014-05-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多