我使用Eclipse并且我一直收到此错误。不知道该怎么办......
我收到此错误
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
SOK_1_SERVER cannot be resolved to a type
SOK_1_SERVER cannot be resolved to a type
at server1.server11.main(server11.java:9)
客户端
package server1;
import java.io.*;
import java.net.*;
import javax.security.sasl.SaslClient;
public class client {
public static void main(String[] args) throws Exception
{
SaslClient CLIENT = new SaslClient() ;
CLIENT.run() ;
}
public void run() throws Exception
{
Socket SOCK = new Socket("localhost", 444) ;
PrintStream PS = new PrintStream(SOCK.getOutputStream()) ;
PS.println("HELLO FROM SERVER!!");
InputStreamReader IR = new InputStreamReader(SOCK.getInputStream()) ;
BufferedReader BR = new BufferedReader(IR) ;
String MESSAGE = BR.readLine() ;
System.out.println(MESSAGE) ;
}
}
服务器端
package server1;
import java.io.*;
import java.net.*;
public class server11
{
public static void main(String[] args) throws Exception
{
SOK_1_SERVER SERVER = new SOK_1_SERVER() ;
SERVER.run() ;
}
public void run() throws Exception
{
ServerSocket SRVSOCK = new ServerSocket(444) ;
Socket SOCK = SRVSOCK.accept() ;
InputStreamReader IR = new InputStreamReader(SOCK.getInputStream());
BufferedReader BR = new BufferedReader(IR) ;
String MESSAGE = BR.readLine() ;
if (MESSAGE != null)
{
PrintStream PS = new PrintStream(SOCK.getOutputStream()) ;
PS.println("MESSAGE RECEIVED!!");
}
}
}
答案 0 :(得分:0)
public static void main(String[] args) throws Exception
{
SOK_1_SERVER SERVER = new SOK_1_SERVER() ;
SERVER.run() ;
}
SOK_1_SERVER必须是类的名称。您是否定义了名为SOK_1_SERVER的类?
我认为你的意思是:
public static void main(String[] args) throws Exception
{
server11 SERVER = new server11();
SERVER.run() ;
}