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)
{
byte[] buf = line.getBytes();
DatagramPacket dp =
new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.1.255"),10002);
ds.send(dp);
if("886".equals(line)) 这个地方的886是先发送出去了,对吗.然后才停止的,如果if放在上面就是直接停止,不会发送出去???
break;
}
}
catch (Exception e)
{
throw new RuntimeException("发送端失败");
}
}
} |
|