关于局域网通信的Socket编程 想做一个简单的程序:1.在局域网中的一个机器上发个消息,其它机器弹出相关窗口显示相关信息。如“下午3点开会,请准时参加!”;2.实现原理要有详细的说明并给个简单代码;.......................谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 window里面不是有一个自带的吧。不过,默认是禁用的,你要把它启动 package client;import java.io.*;import java.net.*;public class Client extends Thread{ private Socket s; private PrintStream ps; private BufferedReader sbr; public Client(){ try{ s=new Socket("192.168.10.94",10000); ps=new PrintStream(s.getOutputStream()); System.out.println("please input"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String line=""; while((line=br.readLine())!=null){ System.out.println("began to send"); ps.println(line); break; } System.out.println("end to send"); sbr=new BufferedReader(new InputStreamReader(s.getInputStream())); //ps.close(); }catch(Exception e){ e.printStackTrace(); } } public void run(){ String myline=""; while(true){ try { while((myline=sbr.readLine())!=null){ System.out.println(myline); } } catch (IOException e) { e.printStackTrace(); } try{ this.sleep(1000); }catch(Exception ex){ ex.printStackTrace(); } } } public static void main(String[] arg){ Client c=new Client(); c.start(); }} package serice;import java.io.*;import java.net.*;public class Serice extends Thread{ private Socket s; private ServerSocket ss; public Serice(){ try { ss=new ServerSocket(10000); } catch (IOException e) { e.printStackTrace(); } } public void run(){ while(true){ try { s=ss.accept(); System.out.println("recive"); BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream())); String line=""; System.out.println("recive2"); //line=br.readLine(); while((line=br.readLine())!=null){ System.out.println("client:"+line); break; } System.out.println("send back"); PrintStream ps=new PrintStream(s.getOutputStream()); String myline=""; BufferedReader mybr=new BufferedReader(new InputStreamReader(System.in)); while((myline=mybr.readLine())!=null){ ps.println(myline); } } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] arg){ Serice service=new Serice(); service.start(); }} 参考3楼的代码,你要通知的那几台机器是客户端,在开机的时候在后台运行一个后台java程序,通过socket连接一个服务器;而发消息的机器连接上服务器后,发送消息给服务器,服务器再转发给连接的客户端,客户端在弹出界面。主要处理就是服务器的转发消息那里和客户端socket弹出界面这里及客户端起动起来隐藏界面的问题。 windows 自带一个 Messenger,默认是禁用的,叫所有员工把它改成启动状态就好了。 大侠帮我解读这行代码 请教高手! 关于焦点的问题 如何创建模板的实例 EJB部署到WebLogic中为何老有错误 请教 JAVA多线程-结束进程 对synchronized的一个疑问 求教!!! 求教:一个正则表达式的写法 (50分)有关finalize()的语言基础问题,求详细的解释~~(解释最详细的至少有40分) weblogic7.0中jar包的移植问题(顶者有分,揭贴前在线等待) Collections,Collection的球别 我设计了一个BorderLayout的窗口,中间以表格显示数据库数据,老报错
import java.net.*;public class Client extends Thread{
private Socket s;
private PrintStream ps;
private BufferedReader sbr;
public Client(){
try{
s=new Socket("192.168.10.94",10000);
ps=new PrintStream(s.getOutputStream());
System.out.println("please input");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null){
System.out.println("began to send");
ps.println(line);
break;
}
System.out.println("end to send");
sbr=new BufferedReader(new InputStreamReader(s.getInputStream()));
//ps.close();
}catch(Exception e){
e.printStackTrace();
}
}
public void run(){
String myline="";
while(true){
try {
while((myline=sbr.readLine())!=null){
System.out.println(myline);
}
} catch (IOException e) {
e.printStackTrace();
}
try{
this.sleep(1000);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
public static void main(String[] arg){
Client c=new Client();
c.start();
}}
import java.net.*;public class Serice extends Thread{
private Socket s;
private ServerSocket ss;
public Serice(){
try {
ss=new ServerSocket(10000);
} catch (IOException e) {
e.printStackTrace();
}
}
public void run(){
while(true){
try {
s=ss.accept();
System.out.println("recive");
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
String line="";
System.out.println("recive2");
//line=br.readLine();
while((line=br.readLine())!=null){
System.out.println("client:"+line);
break;
}
System.out.println("send back");
PrintStream ps=new PrintStream(s.getOutputStream());
String myline="";
BufferedReader mybr=new BufferedReader(new InputStreamReader(System.in));
while((myline=mybr.readLine())!=null){
ps.println(myline);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] arg){
Serice service=new Serice();
service.start();
}
}