WEB开发网
开发学院手机开发Android 开发 Android Socket网络通信 阅读

Android Socket网络通信

 2010-07-15 20:10:00 来源:WEB开发网   
核心提示:String msg = ed_msg.getText().toString();if (socket.isConnected()) {if (!socket.isOutputShutdown()) {out.println(msg);}}}});new Thread(this).start();}public voi

String msg = ed_msg.getText().toString();

if (socket.isConnected()) {

if (!socket.isOutputShutdown()) {

out.println(msg);

}

}

}

});

new Thread(this).start();

}

public void ShowDialog(String msg) {

new AlertDialog.Builder(this).setTitle("提示").setMessage(msg)

.setPositiveButton("OK", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

}

}).show();

}

public void run() {

try {

while (true) {

if(socket.isConnected()){

if(!socket.isInputShutdown()){

if ((content = in.readLine()) != null) {

Log.i("TAG", "++ "+content);

content += " ";

mHandler.sendMessage(mHandler.obtainMessage());

}else{

}

}

}

}

} catch (Exception ex) {

ex.printStackTrace();

}

}

public Handler mHandler = new Handler() {

public void handleMessage(Message msg) {

super.handleMessage(msg);

Log.i("TAG", "-- "+msg);

tv_msg.setText(tv_msg.getText().toString() + content);

}

};

}

package com.Aina.Android;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

import java.io.PrintWriter;

import java.net.Socket;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Android Socket 网络通信

编辑录入:coldstar [复制链接] [打 印]
赞助商链接