www.pudn.com > talk-plugins.rar > ListeningThread.java


package talkServer.business; 
 
import java.io.IOException; 
import java.net.ServerSocket; 
import java.net.Socket; 
 
import org.eclipse.swt.widgets.Text; 
 
 
public class ListeningThread extends Thread { 
	// SET FOR REFERENCE, REFRESH THE DISPLAY 
//	Text text; 
	 
	public ServerSocket server_sock; 
 
	int port = 1860; 
	 
	public ListeningThread(Text text) { 
		super(); 
//		this.text = text; 
	} 
 
	public void run() { 
		super.run(); 
		try { 
			server_sock = new ServerSocket(port); // Server socket. 
		} catch (IOException e1) { 
			e1.printStackTrace(); 
		} 
 
		while (true) { 
			Socket accepted_sock = null; 
			try { 
				accepted_sock = server_sock.accept(); 
			} catch (IOException e2) { 
				e2.printStackTrace(); 
			} 
			// For each socket connection,create a thread to handle it. 
			new ClientHandlerThread(accepted_sock/*, this.text*/).start(); 
		} 
 
	} 
 
	public void destroy() { 
		super.destroy(); 
	} 
 
}