我正在为使用 Socket 的 java 中的 arp 开发客户端和服务器程序。当我编译它时,我得到这样的错误代码看起来像这样。Stack Overflow 向我询问有关我的代码的更多详细信息,但我没有有关此代码的更多详细信息。
import java.io.*;
import java.net.*;
import java.net.Socket.*;
class arpserver
{
public static void main(String args[])throws IOException
{
try
{
ServerSocket soc = new ServerSocket(2500);
System.out.println("Server started");
Socket client = null;
client = soc.accept();
String str;
PrintStream ps = new PrintStream(client.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream()));
Runtime r = Runtime.getRuntime();
Process p = r.exec("ifconfig eth0");
BufferedReader pin=new BufferedReader(new InputStreamReader(p.getInputStream()));
String haddr = "";
String ipaddr = br.readLine();
int flag = 0;
while((str = pin.readLine())!=null)
{
System.out.println(str);
if((str.indexOf("HWaddr")) != -1)
{
int tlen = str.length();
int hlen = tlen - 19;
haddr = str.substring(hlen,tlen);
}
else if ((str.indexOf(ipaddr)) != -1)
{
flag = 1;
}
}
if (flag == 1)
ps.println(haddr);
ps.close();
br.close();
pin.close();
client.close();
soc.close();
}
catch(IOException io)
{
System.err.println("Exception : " + io.toString());
}
}
}
在编译期间我收到此错误
S:\>javac arpserver.java
arpserver.java:12: cannot access Socket
bad class file: .\Socket.java
file does not contain class Socket
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
Socket client = null;
^
1 error