Package java.net

Examples of java.net.DatagramPacket


  private DatagramPacket dgram;
  private String address;
  private int pos;
   
  public DatagramImpl(byte[] buffer, int length, String address) {
    dgram = new DatagramPacket(buffer, length);
               
    if (address != null)
      setAddress(address);
               
    pos = 0;
View Full Code Here


       DatagramSocket socket = new DatagramSocket();

           // send request
       byte[] buf = new byte[256];
       InetAddress address = InetAddress.getByName("192.168.0.41");
       DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4445);
      
       socket.setSoTimeout(1000);
      
       socket.send(packet);

           // get response
       packet = new DatagramPacket(buf, buf.length);
       socket.receive(packet);

       // display response
       String received = new String(packet.getData(), 0, packet.getLength());
       System.out.println("Date of the Moment: " + received);

       socket.close();
      
    } catch (Exception err) {
View Full Code Here

        .info(
            this,
            "Listening for distributed nodes on IP multicast " + iManager.networkMulticastAddress + ":"
                + iManager.networkMulticastPort);

    dgram = new DatagramPacket(recvBuffer, recvBuffer.length);
    try {
      socket = new MulticastSocket(iManager.networkMulticastPort);
      socket.joinGroup(iManager.networkMulticastAddress);
    } catch (IOException e) {
      throw new OIOException(
View Full Code Here

  }

  @Override
  public void startup() {
    try {
      dgram = new DatagramPacket(discoveryPacket, discoveryPacket.length, manager.networkMulticastAddress,
          manager.networkMulticastPort);
      socket = new DatagramSocket();
    } catch (Exception e) {
      OLogManager.instance().error(this, "Can't startup distributed server discovery signaler", e);
    }
View Full Code Here

  private void send(String message) throws Exception
  {
    DatagramSocket ds = new DatagramSocket();
   
    byte[] b = message.getBytes("UTF-8");
    DatagramPacket packet = new DatagramPacket(b, 0, b.length, InetAddress.getLocalHost(), 5040);
 
    ds.send(packet);
  }
View Full Code Here

  protected void doStart() throws Exception
  {   
    _packets = new DatagramPacket[getAcceptors()];
    for (int i = 0; i < getAcceptors(); i++)
    {
      _packets[i] = new DatagramPacket(new byte[MAX_UDP_SIZE], MAX_UDP_SIZE);
    }
    _bufferQueue = new LinkedList<UdpBuffer>();
   
    new Thread(new Processor()).start();
    new Thread(new Processor()).start();
View Full Code Here

    _datagramSocket.close();
  }
 
  public void accept(int acceptorID) throws IOException, InterruptedException
  {
    DatagramPacket p = _packets[acceptorID];
   
    _datagramSocket.receive(p);

    int length = p.getLength();
    if (length == 2 || length == 4) return;
   
    byte[] b = new byte[length];
    System.arraycopy(p.getData(), 0, b, 0, length);
   
    Buffer buffer = new ByteArrayBuffer(b);
   
    UdpBuffer udpBuffer = new UdpBuffer();
    udpBuffer._buffer = buffer;
    udpBuffer._address = p.getAddress();
    udpBuffer._port = p.getPort();
   
    synchronized (_bufferQueue)
    {
      if (_bufferQueue.size() < 1024)
      {
View Full Code Here

      return _remotePort;
    }
   
    public void write(Buffer buffer) throws IOException
    {
      DatagramPacket packet = new DatagramPacket(
          buffer.array(),
          buffer.length(),
          _remoteAddr,
          _remotePort);
      _datagramSocket.send(packet);
View Full Code Here

  public static void main(String[] args) throws Exception
  {
    LoadBalancer server = new LoadBalancer();
    server.start();
    byte[] b = __msg.getBytes();
    DatagramPacket packet = new DatagramPacket(b, b.length);
    packet.setAddress(InetAddress.getLocalHost());
    packet.setPort(5060);
    DatagramSocket socket = new DatagramSocket();
    socket.send(packet);
  }
View Full Code Here

   
    public void send(DnsMessage message) throws IOException
    {
      ByteArrayBuffer buffer = new ByteArrayBuffer(MAX_PACKET_SIZE);
      message.encode(buffer);
      DatagramPacket packet = new DatagramPacket(buffer.asArray(), buffer.length(), _remoteAddr, _remotePort);
     
      _socket = newDatagramSocket();
      _socket.send(packet);
    }
View Full Code Here

TOP

Related Classes of java.net.DatagramPacket

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.