客戶端線程:
class BB1 extends Thread{
public void run()
{
try
{
System.out.println("hahahha");
Socket client=new Socket(ipadress,PORT);
System.out.println(client.getPort());
mingling="ok";
StringReader sr=new StringReader(mingling);
BufferedReader br=new BufferedReader(sr);
PrintWriter pw;
pw=new PrintWriter(client.getOutputStream());
pw.write(br.readLine());
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "數據已經傳輸成功", Toast.LENGTH_SHORT).show();
}
});
pw.close();
br.close();
}
catch(IOException e)
{
e.printStackTrace();
System.out.println("----------------------------------------------");
System.out.println(e.getMessage());
System.out.println("----------------------------------------------");
}
}
}
服務器端線程:
class thread1 implements Runnable
{
private Socket socket;
private ServerSocket ss;
public void run()
{
try{
ss=new ServerSocket(25000);
System.out.println("Server OK");
while(true)
{
socket=ss.accept();
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println("connected!");
System.out.println("you input is:"+br.readLine());
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
異常日志顯示的錯誤:
請各位大神指點迷津~~~~~~~~~~~~~~~~~~~~~~~~
你這是在Android模擬器調試還是使用真機調試的?
如果是模擬器的話,IP用10.225.18.190是連接不上的。
真機的話就要考慮是否其他問題,比如程序是否有訪問網絡的權限。