Strumenti Utente

Strumenti Sito


lpr-b:copyin
no way to compare when less than two revisions

Differenze

Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.


lpr-b:copyin [23/11/2007 alle 13:55 (18 anni fa)] (versione attuale) – creata Marco Danelutto
Linea 1: Linea 1:
 +<code java>
 +package chatMulticast;
  
 +import java.io.IOException;
 +import java.net.DatagramPacket;
 +import java.net.InetAddress;
 +import java.net.MulticastSocket;
 +
 +public class CopyIn extends Thread {
 +
 + int chatPort = 0; 
 + InetAddress chatAddress = null; 
 +
 + final int MAXBUF = 1024; 
 +
 + public  CopyIn(InetAddress ia, int port) {
 + chatPort = port;
 + chatAddress = ia; 
 + }
 +
 + public void run() {
 + MulticastSocket ds = null;
 + try {
 + ds = new MulticastSocket(chatPort);
 + } catch (IOException e) {
 + e.printStackTrace();
 + }
 + try {
 + ds.joinGroup(chatAddress);
 + } catch (IOException e) {
 + e.printStackTrace();
 + }
 + DatagramPacket dp = null; 
 + while (true) {
 + try {
 + dp = new DatagramPacket(new byte[MAXBUF], 0, MAXBUF);
 + ds.receive(dp);
 + } catch (IOException e) {
 + e.printStackTrace();
 + }
 + String line =  new String(dp.getData());
 + System.out.println("From "+dp.getAddress().getHostName()+": "+line);
 + }
 + }
 +
 +}
 +</code>
lpr-b/copyin.txt · Ultima modifica: 23/11/2007 alle 13:55 (18 anni fa) da Marco Danelutto

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki