我是Java和一般网络的新手.我正在读取套接字,并看到ServerSocket类有一个未绑定套接字的构造函数.
我认为套接字连接的工作方式是连接到特定端口.那么如何使用未绑定的ServerSocket呢?
谢谢.
我是第一次使用File类,我有点困惑.
我写了这个基本代码,看看我的桌面上是否有文件被检测到:
public static void main(String[]args){
File test= new File("abc.pdf");
if(test.exists()==true){
System.out.println("got it!");
}
else{System.out.println("try again");}
}
Run Code Online (Sandbox Code Playgroud)
我知道我错过了一大步,因为程序似乎无法检测到它.谁能告诉我还有什么我需要查询的?谢谢.
我试图从Oracle页面运行Hello World RMI示例,但我一直在收到错误.
我一直得到的错误是
服务器异常:java.rmi.NoSuchObjectException:表java.rmi.NoSuchObjectException中没有这样的对象:在sun.rmi.transport.StreamRemoteCall的sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)中的表中没有这样的对象.executeCall(StreamRemoteCall.java:252)at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)at example.hello.Server.main(Server的.java:26)
以下是直接从我使用的网站获取的代码:
Hello接口:
package example.hello;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Hello extends Remote {
String sayHello() throws RemoteException;
}
Run Code Online (Sandbox Code Playgroud)
这是我的服务器类:
package example.hello;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server implements Hello {
public Server() {}
public String sayHello() {
return "Hello, world!";
}
public static void main(String args[]) {
try {
Server obj = new Server();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj,0);
// Bind the remote object's stub …Run Code Online (Sandbox Code Playgroud)