发表于: java/j2ee | 作者: | 日期: 2008/11/07 02:11
标签:

1:字符串与字节数组间的双向转换:

2:UDP接受程序必须先启动运行起来,才能接受UDP发送程序发送的数据;

3: 还学习到了一点DOS的知识:

4: UDP网络程序编写时中文问题的解决:

******************************************************************
这个是发送端的代码:
import java.net.* ;

public class UDPSender
{
public static void main( String[] args ) throws Exception
{
DatagramSocket ds = new DatagramSocket() ;
String str = “米晓辉” ;
ds.send( new DatagramPacket(str.getBytes() ,
str.getBytes().length ,
InetAddress.getByName( “192.168.0.88” ) , 3000)) ;
ds.close() ;
}
}

******************************************************************
这个是接收端的代码:
import java.net.* ;

public class UDPReceiver
{
public static void main( String[] args ) throws Exception
{
DatagramSocket ds = new DatagramSocket( 3000 ) ;
byte[] buf = new byte[1024] ;
DatagramPacket dp = new DatagramPacket(buf , 1024 ) ;
ds.receive( dp ) ;
System.out.println( new String( dp.getData() , 0 , dp.getLength() ) );
System.out.println( dp.getAddress().getHostAddress()) ;
System.out.println( dp.getPort() ) ;
ds.close() ;
}
}

**********************************************************************

: https://blog.darkmi.com/2008/11/07/381.html

本文相关评论 - 1条评论都没有呢
Post a comment now » 本文目前不可评论

No comments yet.

Sorry, the comment form is closed at this time.