@Override public void send(byte[] data) { DatagramPacket packet = new DatagramPacket(data, data.length, this.ip, this.port); try { if (clientSide == null) { System.out.print("could't to connect to server \n"); } else { clientSide.send(packet); getCallback().onConnect(); System.out.print( "client with ip " + this.ip + " sending packet..." + packet.toString() + '\n'); } } catch (IOException ex) { System.out.print("could't to sending data to server because : " + ex.getMessage()); } }
public void run() { try { DatagramSocket socket = new DatagramSocket(); DatagramPacket packet = new DatagramPacket( this.msg.getBytes(), this.msg.length(), InetAddress.getByName(this.url), this.port); while (!Thread.currentThread().isInterrupted()) { socket.send(packet); System.out.println("Sent: " + packet.toString()); Thread.sleep(1); } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }