Facebook
From Speedy Mosquito, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 223
  1. package pl.edu.agh.dsrg.sr.protos;
  2.  
  3. import com.google.protobuf.InvalidProtocolBufferException;
  4.  
  5. import java.net.DatagramPacket;
  6. import java.net.DatagramSocket;
  7. import java.net.InetAddress;
  8.  
  9.  
  10. public class Main {
  11.  
  12.     public static void main(String[] args) throws InvalidProtocolBufferException, InterruptedException {
  13.  
  14.         BankOperationProtos.BankOperation operation;
  15.         DatagramSocket socket = null;
  16.  
  17.         for(int i=0;i<2000;i++) {
  18.             operation= BankOperationProtos.BankOperation.newBuilder().setValue(Math.random()/100+1.0).setType(BankOperationProtos.BankOperation.OperationType.MULTIPLY).build();
  19.             operation.toByteArray();
  20.             try {
  21.                 socket = new DatagramSocket();
  22.                 InetAddress address = InetAddress.getByName("224.0.0.7");
  23.                 byte[] sendBuffer = operation.toByteArray();
  24.                 DatagramPacket sendPacket = new DatagramPacket(sendBuffer, sendBuffer.length, address, 6789);
  25.                 socket.send(sendPacket);
  26.             } catch (Exception e) {
  27.                 e.printStackTrace();
  28.             } finally {
  29.                 if (socket != null)
  30.                     socket.close();
  31.             }
  32.  
  33.             Thread.sleep((long)(Math.random()*10));
  34.         }
  35.  
  36.     }
  37. }