本学期我在一个入门的网络课程中,我们正在使用服务器/客户端聊天室。到目前为止这是我的服务器程序,我无法弄清楚为什么我在标题中收到错误。它显示第17,33和53行的错误,它们都是我命名新类的行。 对我的任何帮助表示赞赏!
import java.io.*;
import java.net.*;
public class Server
{
public static void main(String[] args) throws Exception
{
new MyServer().start(); //Creates new Server for Clients to connect
}
}
public class MyServer() extends Thread
{
ServerSocket SS = new ServerSocket(11200);
Socket S;
ClientManager CM = new ClientManager();
public void run()
{
while(true)
{
S = SS.Accept; //Endless loop allowing clients to repeatedly connect
CM.Add(); //Calls the Add method in ClientManager, which adds the Client to the Array
}
}
}
public class MyClient() extends Thread
{
MyClient Client = new MyClient(Socket, CM);
Scanner S;
public void run()
{
while(true)
{
S = new Scanner(System.in);
CM.SendToAllClients(S); //Calls the method that will send each client the received message
}
}
public void Send(String S)
{
PrintWriter.println(S);
}
}
public class ClientManager()
{
MyClient[] X = new MyClient[15];
int num = 0;
public synchronized void Add(MyClient C)
{
X[num] = C;
num++;
C.start();
}
public synchronized void SendToAllClient(String S)
{
for(i = 0;i < num;i++);
{
X[i].Send(S);
}
}
}
答案 0 :(得分:0)
请勿在课程名称后使用()
:
public class MyServer extends Thread {...}
public class MyClient extends Thread {...}
public class ClientManager {...}