当前位置:编程学习 > JAVA >>

新人看视频出现异常 求高手帮忙解决!~~~~~

注意:ChatDemo.java 使用或覆盖了已过时的 API。
注意:要了解详细信息,请使用 -Xlint:deprecation 重新编译。

这是编译后出现的提示~~~~~~~~~~


以下是代码  照抄的视频 结果悲剧了~~~~~~~
import java.io.*;
import java.net.*;

class Send implements Runnable
{
private DatagramSocket ds;
public Send(DatagramSocket ds)
{
this.ds = ds;
}
public void run()
{
try
{
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));

String line = null;

while((line=bufr.readLine())!=null)
{
if("886".equals(line))
break;

byte[] buf = line.getBytes();

DatagramPacket dp = 
new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.1.8"),10086);
ds.send(dp);
}
}
catch (Exception e)
{
throw new RuntimeException("~~~~");
}
}
}

class Rece implements Runnable
{
private DatagramSocket ds;
public Rece(DatagramSocket ds)
{
this.ds = ds;
}

public void run()
{
try
{
while(true)
{
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf,buf.length);

ds.receive(dp);

String ip = dp.getAddress().getHostAddress();

String data = new String(dp.getData(),dp.getLength());

System.out.println(ip+"~~~~~~~"+data);
}
}
catch (Exception e)
{
throw new RuntimeException("~~~~~~~~~~");
}
}
}


class  ChatDemo
{
public static void main(String[] args) throws Exception
{
DatagramSocket sendS = new DatagramSocket();
DatagramSocket receS = new DatagramSocket(10086);

new Thread(new Send(sendS)).start();
new Thread(new Rece(receS)).start();
}
}
--------------------编程问答-------------------- 先格式化一下吧。用回复内容中的#工具。
补充:Java ,  Java EE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,