This step is to create an instance of the remote object registry Registry on the local host, and specify the port 8888, this step is essential (Java default port is 1099), an indispensable step, the lack of registry creation, then Unable to bind object to remote registry.After running, open the RMI service. The client must be consistent with the service address.
Series links:
SSD8_Ex3 [JAVA_RMI Service] (1) Overview of RMI and Network APIs
SSD8_Ex3[JAVA_RMI](2) Remote Interface Declaration
SSD8_Ex3 [JAVA_RMI] (3) Open RMI Service
SSD8_Ex3 [JAVA_RMI] (4) conference database table
SSD8_Ex3 [JAVA_RMI] (5) database connection and meeting method definition
SSD8_Ex3 [JAVA_RMI] (6) Create Command Line Navigation Menu
MeetingServer.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
Package cn.wangbaiyuan; Import java.net.MalformedURLException; Import java.rmi.AlreadyBoundException; Import java.rmi.Naming; Import java.rmi.NotBoundException; Import java.rmi.RemoteException; Import java.rmi.registry.LocateRegistry; Import java.sql.SQLException; Public class MeetingServer { Private static String Url; Public static boolean start(String port ) { Boolean result=false; Try { // Create a remote object MeetingInterface RemoteMeeting = new RmiDataBase("localhost", 3306, "rmimeeting", "xxxxxxx", "xxxxxxx"); // The instance of the remote object registry Registry on the local host, and the specified port is 8888, this step is essential (Java default port is 1099), an indispensable step, the lack of registry creation, you can not bind the object to On the remote registry LocateRegistry.createRegistry(Integer.parseInt(port)); // Register the remote object on the RMI registry server / / URL binding standard format: rmi://host:port/name (where the protocol name can be omitted, the following two ways are correct) Url="rmi://localhost:"+port+"/RMeeting"; Naming.bind(Url,RemoteMeeting); // Naming.bind("//localhost:8888/RHello",rhello); Result=true; System.err.println(">>>>> INFO: Remote MeetingInterface object binding is successful!"); } Catch (RemoteException e) { System.err.println("An exception occurred while creating a remote object!"); e.printStackTrace(); } Catch (AlreadyBoundException e) { System.err.println("Double binding object exception occurs!"); e.printStackTrace(); } Catch (MalformedURLException e) { System.err.println("URL malformation exception!"); e.printStackTrace(); } Catch (SQLException e) { System.err.println("Error in server connection database!"); e.printStackTrace(); } Return result; } Public static boolean exit(){ Boolean result=false; Try { Naming.unbind("Rmeeting"); Result=true; } Catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } Catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Catch (NotBoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Return false; } } |
This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!
Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/ssd8-ex3-java-rmi-3-open-the-rmi-service-2.html
No Comment