Android,Socket,连接服务器端.net和客户端android?

时间:2016-11-11 06:29:24

标签: android

如何连接服务器在.net但客户端在Android中的套接字? 连接之后我想在服务器发送一些响应之后将一些数据发送到服务器进行登录验证?

1 个答案:

答案 0 :(得分:0)

客户端 private Socket socket; private static final int SERVERPORT = 5000; private static final String SERVER_IP = "10.0.2.2";

try { String str = et.getText().toString();//EDIT TEXT OBJECT PrintWriter out = new PrintWriter(new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())), true); out.println(str); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }

class ClientThread implements Runnable { @Override public void run() { try { InetAddress serverAddr = InetAddress.getByName(SERVER_IP); socket = new Socket(serverAddr, SERVERPORT); } catch (UnknownHostException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } }

使用

new Thread(new ClientThread()).start();