回复 5楼 hhwz
import *;
import *;
import java.awt.*;
import java.awt.event.*;
public class MySocketServer {
public static void main(String[] args){
new ServerService(8000,10);
}
}
class ServiceFrame extends Frame implements Runnable{
ServerService fatherListener;
Socket connectedClient;
TextArea serverMeg;
ServiceFrame(ServerService sv,Socket s){
fatherListener = sv;
connectedClient = s;
setTitle("服务器端socket窗口");
setLayout(new BorderLayout());
serverMeg = new TextArea(10,50);
add("Center",serverMeg);
setVisible(true);
InetAddress clientAddress = connectedClient.getInetAddress();
serverMeg.append("Client connected"+"from\n"+clientAddress.toString()+".\n");
}
public void run(){
try{
BufferedReader sIn = new BufferedReader(new InputStreamReader(connectedClient.getInputStream()));
PrintWriter sOut = new PrintWriter(connectedClient.getOutputStream());
sOut.println("Hello! Wellcome connect to our server!\r");
sOut.flush();
String s = sIn.readLine();
while(!s.equals("Bye")){
serverMeg.append("Client端输入的信息为:\n"+s);
s = sIn.readLine();
}
connectedClient.close();
}catch(Exception e){}
fatherListener.addMeg("Client"+"closed."+"\n");
dispose();
}
}
class ServerService extends Frame{
ServerSocket m_sListener;
TextArea listenerMeg;
public ServerService(int Port,int Count){
try{
m_sListener = new ServerSocket(Port,Count);
setTitle("服务器端监听服务窗口");
this.addWindowListener(new WinAdpt());
setLayout(new BorderLayout());
listenerMeg = new TextArea("监听服务已经启动\n",10,50);
add("Center",listenerMeg);
setVisible(true);
while(true){
Socket connected = m_sListener.accept();
InetAddress clientAddress = connected.getInetAddress();
listenerMeg.append("Client"+"connected"+"from\n"+clientAddress.toString()+".\n");
ServiceFrame myST1 = new ServiceFrame(this,connected);
Thread myST2 = new Thread(myST1);
myST2.start();
}
}catch(IOException e){}
}
public void addMeg(String s){
listenerMeg.append(s);
}
}
class WinAdpt extends WindowAdapter{
public void windowClosing(WindowEvent e){
(e.getWindow()).dispose();
System.exit(0);
}
}
服务器不用applet,能帮忙弄得符合要求吗,只会基本的代码,怎么连接Access 并且判断是查询还是更新 并且回显到客户端这个不太会