我无法解决这个问题,这似乎是微不足道但却无法抓住它......
public static void handleClient(){
System.out.println("Opening PORT...");
Socket link = null;
try{
link =servSock.accept();
Scanner input = new Scanner(link.getInputStream());
PrintWriter output = new PrintWriter(link.getOutputStream(),true);
String message = input.nextLine();
String username = null;
if (message.startstWith("username"))
{
username = message.subString(7);
output.println("Your username is: "+ username);
System.out.println(username+" is connecting...");
message = input.nextLine();
while (!message.equals("*END*"))
{
System.out.println(username +" Says: "+message);
output.println("we received your message..");
}
}else{
output.println("PLEASE VERIFY hostname...");
}
我收到来自套接字流的内容并将其另存为String
String message = input.nextLine();
这是我编译时的结果
C:\Users\==\Desktop\anoterTest>javac TCPServer.java
TCPServer.java:51: error: cannot find symbol
if (message.startstWith("username"))
^
symbol: method startstWith(String)
location: variable message of type String
TCPServer.java:54: error: cannot find symbol
username = message.subString(0,8);
^
symbol: method subString(int,int)
location: variable message of type String
2 errors
C:\Users\==\Desktop\anoterTest>
答案 0 :(得分:2)
startstWith
应为startsWith
(拼写错误)
和
subString
应为substring
Java方法区分大小写
答案 1 :(得分:1)
您拼错startsWith
startstWith
。您还错误substring
subString
- 大写问题。
答案 2 :(得分:0)