-
Notifications
You must be signed in to change notification settings - Fork 0
/
WirelessSender.java
49 lines (43 loc) · 1.07 KB
/
WirelessSender.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.net.*;
import javax.swing.*;
import java.util.Properties;
public class WirelessSender implements Runnable
{
MulticastSocket ms;
byte[] sendbyte;
public boolean status=true;
Thread t;
String nodename,whois;
int distance,portno;
WirelessSender(String nodename,int portno,String whois,int distance)
{
this.nodename=nodename;
this.portno=portno;
this.whois=whois;
this.distance=distance;
t=new Thread(this);
t.start();
}
public void run()
{
try
{
ms=new MulticastSocket(5454);
InetAddress ia=InetAddress.getByName("228.2.5.1");
ms.joinGroup(ia);
Thread.sleep(5000);
while(status)
{
String sendmsg=whois+":"+nodename+":"+portno+":"+distance+":"+InetAddress.getLocalHost().getHostName();
sendbyte=sendmsg.getBytes();
DatagramPacket dp=new DatagramPacket(sendbyte,sendbyte.length,ia,5454);
ms.send(dp);//sends to all subscribers with the port no 5454
Thread.sleep(1200);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}