Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
}<br />
Toast.makeText(this, text, Toast.LENGTH_LONG).show();<br />
}<br />
//--update conversation 5<br />
public void updateConversation(final String text) {<br />
// use handler to update UI from thread;<br />
handler.post(new Runnable() {<br />
public void run() {<br />
textConver.append(text);<br />
}<br />
});<br />
}<br />
5. แก้ไขโค้ดในไฟล์ ServerTCP.java เพื่อกำหนดการทำงานในส่วนของเซิร์ฟเวอร์ดังนี้<br />
package com.test.network.tcp;<br />
import java.io.BufferedInputStream;<br />
import java.io.BufferedOutputStream;<br />
import java.io.DataInputStream;<br />
import java.io.DataOutputStream;<br />
import java.io.IOException;<br />
import java.net.ServerSocket;<br />
import java.net.Socket;<br />
import android.util.Log;<br />
// -- TCP Server call when run as Server<br />
public class ServerTCP implements Runnable {<br />
public static final String TAG = "ServerTCP Log";<br />
private ServerThread clients;<br />
private ServerSocket server = null;<br />
private Thread thread = null;<br />
private BasicNetworkTCPActivity _uclient;<br />
public ServerTCP(BasicNetworkTCPActivity uclient,int port) {<br />
_uclient = uclient;<br />
try {<br />
Log.d(TAG, "Binding to port " + port + ", please wait ...");<br />
server = new ServerSocket(port);<br />
Log.d(TAG, "Server started: " + server);<br />
start();<br />
_uclient.updateStatus("Server started: " + server);<br />
} catch (IOException ioe) {<br />
_uclient.updateStatus("Can not bind to port " + port + ": " + ioe.getMessage());<br />
}<br />
}<br />
public void run() {<br />
while (thread != null) {<br />
try {<br />
Log.d(TAG, "Waiting for a client ...");<br />
// add new client<br />
clients = new ServerThread(this,server.accept());<br />
บทที ่ 10 การพัฒนาแอพพลิเคชันติดต่อบนเครือข่ายอย่างง่าย 203