帮帮忙,好吗,主要是socket和client双向通讯比较模糊
解决方案 »
- 有人做一个软件同时使用java、C#的吗
- 在JAVA中怎么用 MessageDigest实现MD5的加密?
- 谁有PowerDesigner的入门教程.. 和八种类关系的解析... 设计模式课程!!
- File类的 renameTo 方法
- 打印问题(急。。。。)
- swing中的图片问题
- 如何把一张图片下载到本地?
- sql 的ResultSet 的cursor 移不动,它有几个field 是定义数据集的属性的,但没提供set 方法
- 用java运行class总是不通过
- 见笑了
- 用com.sun.java.swing 里的japplet 代替 原来的applet是不是可以啊???
- wegblogic問題
public void run(){
try{
sleep(100);
Chat.ServerListen();
}catch(Exception e){
e.printStackTrace();
}
}
}public class Chat extends Form
{
public static int PORT=8080;
public Client client;
public Chat(){
super();
initForm();
ThreadListen threadlisten=new ThreadListen();
threadlisten.start();
client=new Client();
} public static void ServerListen(){
Server server=new Server();
server.listen();
} public static void main(String args[])
{
Application.run(new Chat());
} public void dispose()
{
super.dispose();
components.dispose();
} private void button1_click(Object source, Event e){
client.SendMsg();
}客户端:(Client.java)
public class Client{
public PrintWriter out;
public Socket socket;
public Client(){
try {
InetAddress add=InetAddress.getByName(null);
int intIndex=add.toString().indexOf("/");
String strAdd=add.toString().substring(10);
socket=new Socket(strAdd,Chat.PORT);
}catch(Exception e){
e.printStackTrace();
}
}
public void SendMsg() {
try{
out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
out.println("howdy");
}catch(Exception e){
e.printStackTrace(); }
}
}服务端:(Server.java)
public class Server{
public static String strMess="";
public static ServerSocket s;
public static Socket socket;
public static BufferedReader in;
public static PrintWriter out;
public Server(){
try{
s= new ServerSocket(Chat.PORT);
socket=s.accept();
}catch (Exception e){
e.printStackTrace();
}
}
public static void listen()
throws com.ms.wfc.io.IOException{
try{
while (true){
in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
AcceptMess();
}
}catch(IOException e ){
e.printStackTrace();
}
}
public static void AcceptMess()
throws IOException{
if (true){
strMess=in.readLine();
MessageBox.show(strMess+"OK!");
}
}
}
没有Form类呀