Hallo,
ich versuche schon seit langer Zeit einen einfachen TCP Client in meine App einzubauen. Jedoch scheitere ich schon beim Starten des Sockets.
InetAddress ia;
ia = java.net.InetAddress.getByName(TbIp.getText().toString());
Socket s = new Socket(ia, 8000);
Logcat sagt:
10-02 23:24:05.628: E/AndroidRuntime(15687): FATAL EXCEPTION: main
10-02 23:24:05.628: E/AndroidRuntime(15687): android.os.NetworkOnMainThreadException
10-02 23:24:05.628: E/AndroidRuntime(15687): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
10-02 23:24:05.628: E/AndroidRuntime(15687): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
10-02 23:24:05.628: E/AndroidRuntime(15687): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
10-02 23:24:05.628: E/AndroidRuntime(15687): at libcore.io.IoBridge.connect(IoBridge.java:112)
10-02 23:24:05.628: E/AndroidRuntime(15687): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
10-02 23:24:05.628: E/AndroidRuntime(15687): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
10-02 23:24:05.628: E/AndroidRuntime(15687): at java.net.Socket.startupSocket(Socket.java:566)
10-02 23:24:05.628: E/AndroidRuntime(15687): at java.net.Socket.<init>(Socket.java:225)
10-02 23:24:05.628: E/AndroidRuntime(15687): at com.example.tcptest.MainActivity$1.onClick(MainActivity.java:42)
10-02 23:24:05.628: E/AndroidRuntime(15687): at android.view.View.performClick(View.java:3591)
10-02 23:24:05.628: E/AndroidRuntime(15687): at android.view.View$PerformClick.run(View.java:14263)
10-02 23:24:05.628: E/AndroidRuntime(15687): at android.os.Handler.handleCallback(Handler.java:605)
10-02 23:24:05.628: E/AndroidRuntime(15687): at android.os.Handler.dispatchMessage(Handler.java:92)
10-02 23:24:05.628: E/AndroidRuntime(15687): at android.os.Looper.loop(Looper.java:137)
10-02 23:24:05.628: E/AndroidRuntime(15687): at android.app.ActivityThread.main(ActivityThread.java:4507)
10-02 23:24:05.628: E/AndroidRuntime(15687): at java.lang.reflect.Method.invokeNative(Native Method)
10-02 23:24:05.628: E/AndroidRuntime(15687): at java.lang.reflect.Method.invoke(Method.java:511)
10-02 23:24:05.628: E/AndroidRuntime(15687): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
10-02 23:24:05.628: E/AndroidRuntime(15687): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
10-02 23:24:05.628: E/AndroidRuntime(15687): at dalvik.system.NativeStart.main(Native Method)
10-02 23:24:56.788: I/Process(15687): Sending signal. PID: 15687 SIG: 9
Vielen Dank für eure Hilfe!