首先,我对此很陌生,我有服务器/客户端套接字在运行,服务器正在发送/接收数据,但我的客户端目前仅在 try/catch 块中发送数据,我需要编写另一种方法来只是捕捉传入的数据?并将其保留在我原来的 try/ctach* 之外
任何帮助都会很棒
public void onClick(View v)
{
setMyIp(ipaddress.getText().toString());
// myComs.sending_data(getMyIp() , "Got connected");
try
{
InetAddress inet = InetAddress.getByName(getMyIp());
Socket s = new Socket(inet, 2000);
OutputStream o = s.getOutputStream();
PrintWriter p = new PrintWriter(o);
InputStream in = s.getInputStream();
p.println("You are connected");
p.flush();
readContacts();
//inboxConversations();
//outboxConversations();
readSms();
}
catch (UnknownHostException e)
{
ipaddress.setText("Unknown host");
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
这是我的代码,我需要在按钮之外创建一个单独的侦听器任何想法
谢谢