import java.io.IOException;
import java.net.*;
class Send { /**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
DatagramSocket ds=new DatagramSocket();
byte[] b="hello world".getBytes();
DatagramPacket dp=new DatagramPacket(b,b.length,InetAddress.getLocalHost(),5555);
ds.send(dp);
ds.close(); }}
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
class receive { /**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
DatagramSocket ds=new DatagramSocket(5555);
byte[] b=new byte[1024];
DatagramPacket dp=new DatagramPacket(b,b.length);
ds.receive(dp);
System.out.println("信息已收到");
ds.close();
}}
帮我看看怎么我的主机在启动本机收包时好象进入死循环一样?
import java.net.*;
class Send { /**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
DatagramSocket ds=new DatagramSocket();
byte[] b="hello world".getBytes();
DatagramPacket dp=new DatagramPacket(b,b.length,InetAddress.getLocalHost(),5555);
ds.send(dp);
ds.close(); }}
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
class receive { /**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException
{
DatagramSocket ds=new DatagramSocket(5555);
byte[] b=new byte[1024];
DatagramPacket dp=new DatagramPacket(b,b.length);
ds.receive(dp);
System.out.println("信息已收到");
ds.close();
}}
帮我看看怎么我的主机在启动本机收包时好象进入死循环一样?
DatagramPacket dp=new DatagramPacket(b,b.length,InetAddress.getByName("127.0.0.1"),5555);
可以接受到数据包。用InetAddress.getLocalHost()柱塞,打印出我的本机地址feng/0.1.0.5。