Strumenti Utente

Strumenti Sito


lpr-b-2007-2008:copyout
package chatMulticast;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
 
public class CopyOut extends Thread {
 
	InetAddress chatAddress = null; 
	int chatPort = 0; 
 
	public CopyOut(InetAddress chat, int port) {
		chatAddress = chat;
		chatPort = port; 
	}
 
	public void run() {
		DatagramSocket ds = null;
		try {
			ds = new DatagramSocket();
		} catch (SocketException e) {
			e.printStackTrace();
		} 
		BufferedReader in
		   = new BufferedReader(new InputStreamReader(System.in));
		String line = null;
		try {
			line = in.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		} 
		do {
			DatagramPacket dp = new DatagramPacket(line.getBytes(),0, line.getBytes().length);
			dp.setAddress(chatAddress);
			dp.setPort(chatPort);
			try {
				ds.send(dp);
			} catch (IOException e) {
				e.printStackTrace();
			}
			try {
				line = in.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
		} while(line != null);
 
	}
}
lpr-b-2007-2008/copyout.txt · Ultima modifica: 19/09/2008 alle 14:08 (11 anni fa) (modifica esterna)