import java.io.*;
import java.net.*;
class Send implements Runnable
{
private DatagramSocket ds;
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[] by=line.getBytes();
DatagramPacket dp=new DatagramPacket(by,by.length,InetAddress.getByName("192.168.0.109"),10005);
ds.send(dp);
if ("886".equals(line))
{
break;
}
}
}
catch (Exception e)
{
throw new RuntimeException("send is fail");
}
}
}
class Rece implements Runnable
{
private DatagramSocket ds;
Rece(DatagramSocket ds)
{
this.ds=ds;
}
public void run()
{
try
{
byte[] by=new byte[1024];
DatagramPacket dp=new DatagramPacket(by,by.length);
ds.receive(dp);
String ip=dp.getAddress().getHostAddress();
String date=new String(dp.getData(),0,dp.getLength());
if ("886".equals(date))
{
System.out.println("lev room");
break;
}
}
catch (Exception e)
{
throw new RuntimeException("Rece is fail");
}
}
}
class ChatText
{
public static void main(String[] args)
{
DatagramSocket sendSocket=new DatagramSocket();
DatagramSocket receSocket=new DatagramSocket(10005);
new Thread(new send(sendSocket)).start();
new Thread(new send(receSocket)).start();
}
}
|
|