Sebastian Rieger
7 years ago
2 changed files with 48 additions and 48 deletions
-
46VerteilteSysteme-Examples/src/verteiltesysteme/socket/multicast/UDPMulticastConsumer.java
-
50VerteilteSysteme-Examples/src/verteiltesysteme/socket/multicast/UDPMulticastProducer.java
@ -1,23 +1,23 @@ |
|||
package verteiltesysteme.socket.multicast; |
|||
|
|||
import java.net.*; |
|||
|
|||
class UDPMulticastConsumer { |
|||
public static void main(String args[]) throws Exception { |
|||
String groupname = "224.1.1.1"; |
|||
int udpPort = 36040; |
|||
@SuppressWarnings("resource") |
|||
MulticastSocket mcastSocket = new MulticastSocket(udpPort); |
|||
InetAddress IPAddress = InetAddress.getByName(groupname); |
|||
mcastSocket.joinGroup(IPAddress); |
|||
|
|||
byte[] receiveData = new byte[1024]; |
|||
|
|||
while (true) { |
|||
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); |
|||
mcastSocket.receive(receivePacket); |
|||
String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength()); |
|||
System.out.println(sentence); |
|||
} |
|||
} |
|||
} |
|||
package verteiltesysteme.socket.multicast; |
|||
|
|||
import java.net.*; |
|||
|
|||
class UDPMulticastConsumer { |
|||
public static void main(String args[]) throws Exception { |
|||
String groupname = "224.1.1.1"; |
|||
int udpPort = 36041; |
|||
@SuppressWarnings("resource") |
|||
MulticastSocket mcastSocket = new MulticastSocket(udpPort); |
|||
InetAddress IPAddress = InetAddress.getByName(groupname); |
|||
mcastSocket.joinGroup(IPAddress); |
|||
|
|||
byte[] receiveData = new byte[1024]; |
|||
|
|||
while (true) { |
|||
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); |
|||
mcastSocket.receive(receivePacket); |
|||
String sentence = new String(receivePacket.getData(), 0, receivePacket.getLength()); |
|||
System.out.println(sentence); |
|||
} |
|||
} |
|||
} |
@ -1,25 +1,25 @@ |
|||
package verteiltesysteme.socket.multicast; |
|||
|
|||
import java.io.*; |
|||
import java.net.*; |
|||
|
|||
class UDPMulticastProducer { |
|||
public static void main(String args[]) throws Exception { |
|||
String groupname = "224.1.1.1"; |
|||
int udpPort = 36040; |
|||
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); |
|||
MulticastSocket mcastSocket = new MulticastSocket(udpPort); |
|||
InetAddress IPAddress = InetAddress.getByName(groupname); |
|||
mcastSocket.joinGroup(IPAddress); |
|||
|
|||
byte[] sendData = new byte[1024]; |
|||
|
|||
String sentence = inFromUser.readLine(); |
|||
sendData = sentence.getBytes(); |
|||
|
|||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, udpPort); |
|||
mcastSocket.send(sendPacket); |
|||
mcastSocket.leaveGroup(IPAddress); |
|||
mcastSocket.close(); |
|||
} |
|||
} |
|||
package verteiltesysteme.socket.multicast; |
|||
|
|||
import java.io.*; |
|||
import java.net.*; |
|||
|
|||
class UDPMulticastProducer { |
|||
public static void main(String args[]) throws Exception { |
|||
String groupname = "224.1.1.1"; |
|||
int udpPort = 36041; |
|||
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); |
|||
MulticastSocket mcastSocket = new MulticastSocket(udpPort); |
|||
InetAddress IPAddress = InetAddress.getByName(groupname); |
|||
mcastSocket.joinGroup(IPAddress); |
|||
|
|||
byte[] sendData = new byte[1024]; |
|||
|
|||
String sentence = inFromUser.readLine(); |
|||
sendData = sentence.getBytes(); |
|||
|
|||
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, udpPort); |
|||
mcastSocket.send(sendPacket); |
|||
mcastSocket.leaveGroup(IPAddress); |
|||
mcastSocket.close(); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue