Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2004, 12:05 AM
kiw kiw is offline
Registered User
 
Join Date: Oct 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default UDP data tranmission?

 I have a SNTP client Pro.£¬It needs send 48byte data packet to SNTP server¡£But "Timeout" appear when I runnig it£¬is the udp data type wrong£¿


    DatagramSocket so = new DatagramSocket(13);
    so.setSoTimeout(8000);
    int clientms[] = new int[48];
    clientms[0]=0x23; //the first 8 bit'00100011' means it's a client
,VISION 4;
    byte[] data = new byte[48]; //sntp message has 48 byte;

    for (int i=0;i<48;i++) {
       data[i] = (byte) clientms[i]; //int array convert to byte array
       System.out.print(data[i]+" ");
      }
    DatagramPacket packet = new DatagramPacket(data,data.length,
    InetAddress.getByName(machine),daytimeport);

    so.send(packet);

    packet.setData(new byte[48]);
    so.receive(packet); //If server response£¬the it return 48byte data

    String inMessage=new String(packet.getData(),0,data.length);
    System.out.println("received message: "+ inMessage);
    so.close();





Similar Threads
Thread Thread Starter Forum Replies Last Post
Radius Client UDP packet problem netraju C# 2 April 5th, 2008 12:41 AM
Implementing some broadcast udp protocol AliJ General .NET 0 February 26th, 2007 03:11 AM
Implementing some broadcast udp protocol AliJ C# 0 February 23rd, 2007 09:51 AM
Implementing some broadcast udp protocol AliJ C# 2005 0 February 23rd, 2007 09:34 AM
asynchronous UDP socket Roland Wrox Book Feedback 0 June 26th, 2003 10:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.