Topic: sntp客户端的UDP传输问题? |
Print this page |
1.sntp客户端的UDP传输问题? | Copy to clipboard |
Posted by: flyingdd Posted on: 2004-12-15 11:44 我做了一个SNTP的客户端程序,需要向服务器发送48byte的数据包。运行提示超时,我想问题可能出在udp数据传送上了。哪位高手帮我看看? DatagramSocket so = new DatagramSocket(123); so.setSoTimeout(8000); int clientms[] = new int[48]; clientms[0]=0x23; //sntp客户端发送包信息的前8个bit为'00100011' byte[] data = new byte[48]; //sntp message has 48 byte; for (int i=0;i<48;i++) { data[i] = (byte) clientms[i]; //将int数组转化为byte数组 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); //如果服务器响应,将返回48byte信息 System.out.println(); byte data1[] = packet.getData(); for (int i=0;i<48;i++) { System.out.print(data1[i]+" "); } so.close(); |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |