Android 与电脑的Socket通信为什么不能接收数据
将电脑作为服务端,android平板作为客户端,进行同一局域网下的TCP的socket通信,结果测试时发现可以android客户端可以向电脑发送数据缺接受不到数据,求大神帮忙看看什么问题
public static String receiveData;
public static Socket s;
public static BufferedReader in;
public static BufferedWriter out;
public static void connect(){
new Thread() {
public void run() {
try {//打开app后按下一个按钮开启连接,可以连接上
s = new Socket("192.168.0.100", com.android.dafenqi.MainActivity.port);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
//每次按下一个按钮便调用下面的send()方法接受和发送数据,接受在前时,便不能发送,发送在前电脑服务端能正常收到数据,就是android接受数据时卡住了,接受不到
public static void send() {
try {
//receiveData = in.readLine();这时能发送数据,但不能接收数据,去掉//就连数据都不能发了
out.write(sendData + "\n");
out.flush();
receiveData = in.readLine();
/*byte[] datas = new byte[2048];
//从服务端程序接收数据
s.getInputStream().read(datas);
com.android.dafenqi.ScoketClient.receiveData=new String(datas);*/
} catch (Exception e) {
e.printStackTrace();
}
}