資源簡介
局域網廣播,含有客戶端和服務器端。
計算機網絡。

代碼片段和文件信息
package?client;
import?java.awt.*;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.net.*;
import?javax.swing.*;
public?class?Receive??extends?Jframe?implements?RunnableActionListener{
private?static?final?long?serialVersionUID?=?1L;
JMenuBar?menu=new?JMenuBar();
JMenu?m1=new?JMenu(“開始“);
JMenu?m2=new?JMenu(“幫助“);
JMenuItem?itemStart=new?JMenuItem(“開始收聽“);
JMenuItem?itemStop=new?JMenuItem(“停止收聽“);
JMenuItem?exit=new?JMenuItem(“退出“);
JMenuItem?help=new?JMenuItem(“關于“);
JTextArea?info=new?JTextArea(3020);
JButton?start=new?JButton(“開始收聽“);
JButton?stop=new?JButton(“停止收聽“);
JPanel?northPane=new?JPanel();
JScrollPane?centerPane=new?JScrollPane(info);
Container?con=this.getContentPane();
String?line=““;
private?static?final?int?PORT=2012;
InetAddress?group;
MulticastSocket?socket;
boolean?ting=false;
Thread?thread;
public?Receive(){
????thread=new?Thread(this);?
con.setLayout(new?BorderLayout());
con.add(northPaneBorderLayout.NORTH);
con.add(centerPaneBorderLayout.CENTER);
menu.add(m1);
menu.add(m2);
m1.add(itemStart);
m1.add(itemStop);
m1.add(exit);
m2.add(help);
northPane.add(new?JLabel(“收聽廣播“));
northPane.add(start);
northPane.add(stop);
info.setEditable(false);
exit.addActionListener(this);
help.addActionListener(this);
start.addActionListener(this);
itemStart.addActionListener(this);
stop.addActionListener(this);
itemStop.addActionListener(this);
????validate();
try{???
?????????group=InetAddress.getByName(“224.1.0.0“);?????
?????????socket=new?MulticastSocket(PORT);???????????????
?????????socket.joinGroup(group);??????????????
???????????????????????????????????????????????
???????}???
????catch(Exception?e){
????
????}
?
setSize(470?500);
setJMenuBar(menu);
setResizable(false);
this.setLocation(400100);
settitle(“局域網廣播“);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setVisible(true);
}
public?void?actionPerformed(ActionEvent?e){
if(e.getSource()==exit){
this.dispose();
}
if(e.getSource()==help){
String?me=“局域網廣播“;
JOptionPane.showMessageDialog(thisme);
}
if(e.getSource()==start){
System.out.println(“&&&“);
if(!(thread.isAlive())){
thread=new?Thread(this);
}
try{
thread.start();
ting?=false;
}catch(Exception?ee){
String?info=“接收異常“;
JOptionPane.showMessageDialog(null?info?“提示?“JOptionPane.INFORMATION_MESSAGE);
return;
}
}
if(e.getSource()==stop){
System.out.println(“$$$$“);
thread.interrupt();????
????????ting=true;????
}
}
public?void?run()?{??
info.setText(“接收的內容:\n“);
while(true){?????
???????byte?data[]=new?byte[8192];???
???????System.out.println?(“xxxxx“);
???????DatagramPacket?packet=new?DatagramPacket(datadata.lengthgroupPORT);?????
???????try{?????
???????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3526??2009-12-11?22:04??client\Receive.java
?????文件???????4957??2009-12-11?22:46??server\BroadCast.java
?????目錄??????????0??2009-12-08?22:05??client
?????目錄??????????0??2009-12-08?22:06??server
-----------?---------??----------?-----??----
?????????????????8483????????????????????4
- 上一篇:struts2 論壇系統
- 下一篇:rpmrebuild工具包親測可用
評論
共有 條評論