-3
夥計們,當我運行它時,我的代碼出現問題,連接到服務器併發送消息,但在此之後停止。任何建議如何處理我的套接字
public void onClick(View arg0)
{ serverIP=Ip.getText().toString();
new Thread(new Runnable() {
@Override
public void run() {
try {
clientSocket= new Socket(serverIP,serverPort);//making the socket connection
printWriter=new PrintWriter(clientSocket.getOutputStream());
String connect="connected to server";
printWriter.write(connect);
printWriter.flush();
printWriter.close();
clientSocket.close();
Toast.makeText(getApplicationContext(),"Connected to:"+serverIP+" on port:"+serverPort,Toast.LENGTH_LONG).show();
} catch (UnknownHostException e) {
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}).start();
}
});
如果有錯誤,那將是非常有用的信息。 –
@JeffreyBlattman我上傳了我的logcat,但我不知道如何讓圖片顯示在沒有鏈接的同一頁上stackoverflow –