[求助]大家帮我改改
你们好,请问那个服务端为什么不能监听到客户端的话,客户端也不能传话到服务端,能帮我改改吗?帮不同色的笔必出来,让我自己好好揣摩!十分感谢!
搜索更多相关的解决方案:
改改
----------------解决方案--------------------------------------------------------
这里是代码!
谢谢你们了!
----------------解决方案--------------------------------------------------------
可以了,只是服务器端出了点小状况;
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
public class Server
{
public static void main(String[] args)
{
ServerService MyServer=new ServerService(6000,10);
}
}
class ServiceThread extends Frame implements Runnable
{
ServerService FatherListener;
Socket ConnectedClient;
Thread ConnectThread;
Panel ListenerPanel;
TextArea ServerMeg;
public ServiceThread(ServerService sv,Socket s){
FatherListener=sv;
ConnectedClient=s;
ConnectThread=new Thread(this);
setTitle("Server(服务器端)");
setLayout(new BorderLayout());
ServerMeg=new TextArea(13,50);
add("Center",ServerMeg);
setResizable(true);
pack();
setVisible(true);
InetAddress ClientAddress=ConnectedClient.getInetAddress();
ServerMeg.append("Server connect"+" to:\n\n"+ClientAddress.toString()+".\n");
}
public void run(){
try{
DataInputStream in =new DataInputStream(new BufferedInputStream(ConnectedClient.getInputStream()));
PrintStream out=new PrintStream(new BufferedOutputStream(ConnectedClient.getOutputStream()));
out.println("Hello!,Welcome connect to me(server)!\r");
out.flush();
String s=in.readLine();
System.out.println(s);
while(!s.equals("Bye")){
ServerMeg.append("client 端输入的信息为:\n"+s);
s=in.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(6000);
setTitle("Server Listener(监听器窗口)");
this.addWindowListener(new WinAdpt());
setLayout(new BorderLayout());
ListenerMeg=new TextArea("[监听服务已启动]\n\n\n",10,50);
add("Center",ListenerMeg);
setResizable(true);
pack();
setVisible(true);
while(true){
Socket Connected=m_sListener.accept();
InetAddress ClientAddress=Connected.getInetAddress();
ListenerMeg.append("Client "+" connected "+"from:\n\n"+ClientAddress.toString()+".\n");
ServiceThread MyST=new ServiceThread(this,Connected);
MyST.ConnectThread.start();
}
}
catch (IOException e){}
}
public void addMeg(String s){
ListenerMeg.append(s);
}
}
class WinAdpt extends WindowAdapter{
public void windowClosing(WindowEvent e){
((Frame)e.getWindow()).dispose();
System.exit(0);
}
}
----------------解决方案--------------------------------------------------------
不是吧,我用那客户端发信息,那服务器都接收不到,也不响应!只是监示到IP
能不能再指教?!谢谢
----------------解决方案--------------------------------------------------------
我在我的机子上可以的。
----------------解决方案--------------------------------------------------------
哦,那就奇怪了!我的机收不了信息!
----------------解决方案--------------------------------------------------------