Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.DatagramPacket;
- import java.net.DatagramSocket;
- import java.sql.SQLSyntaxErrorException;
- public class Server {
- public static void main(String[] args) {
- try {
- DatagramSocket datagramSocket = new DatagramSocket(4567);
- byte[] recieved_message = new byte[60000];
- DatagramPacket datagramPacket = null;
- while(true) {
- datagramPacket = new DatagramPacket(recieved_message, recieved_message.length);
- datagramSocket.receive(datagramPacket);
- String s = from_bytes_to_string(recieved_message).toString();
- System.out.println(s);
- if(s.charAt(0) == 'E' && s.charAt(1) == 'N' && s.charAt(2) == 'D') {
- return;
- }
- recieved_message = new byte[60000];
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static StringBuilder from_bytes_to_string(byte[] b) {
- StringBuilder s = new StringBuilder();
- for(int i = 0; i < b.length; i++) {
- s.append((char)b[i]);
- }
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement