在android中创建套接字时出错

时间:2012-04-03 15:28:42

标签: android python sockets android-emulator

我正在尝试从Android应用程序连接到python服务器。代码适用于java,但是当我在python中尝试相同的代码时,我在我的应用程序中弹出一个表示PROJECT_NAME很可能因以下错误而停止:

04-03 22:06:16.575: E/AndroidRuntime(678):  at java.lang.reflect.Method.invokeNative(Native Method)
04-03 22:06:16.575: E/AndroidRuntime(678):  at java.lang.reflect.Method.invoke(Method.java:511)
04-03 22:06:16.575: E/AndroidRuntime(678):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-03 22:06:16.575: E/AndroidRuntime(678):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-03 22:06:16.575: E/AndroidRuntime(678):  at dalvik.system.NativeStart.main(Native Method)
04-03 22:06:21.555: I/Process(678): Sending signal. PID: 678 SIG: 9

我已经有了这段代码:

        public void onClick(View v) {
            try {
                address = InetAddress.getByName("localhost");
                socket = new Socket(address, port);
                System.out.println("Connecting to " + address + " on port "
                        + port);
                System.out.println("Just connected to "
                        + socket.getRemoteSocketAddress());
                out = new DataOutputStream(socket.getOutputStream());


                in = new DataInputStream(socket.getInputStream());



            } catch (UnknownHostException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                System.out.println("IOE");
            }

0 个答案:

没有答案