通过tcp连接的软件源码
public class MainActivity extends Activity implements OnClickListener {
private Button bnConnect;
private TextView txReceive;
private EditText edIP, edPort, edData;
private Handler handler = new Handler(Looper.getMainLooper());
private TcpClient client = new TcpClient() {
@Override
public void onConnect(SocketTransceiver transceiver) {
refreshUI(true);
}
@Override
public void onDisconnect(SocketTransceiver transceiver) {
refreshUI(false);
}
@Override
public void onConnectFailed() {
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "连接失败",
Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onReceive(SocketTransceiver transceiver, final String s) {
handler.post(new Runnable() {
@Override
public void run() {
txReceive.append(s);
}
});
}
};
评论