RMI very slow is client and server are not in the same machine - performance

i have a strange problem. I developed client-server application with Java RMI, and in the localhost work very fine, also work very well if i put the client and server on two different MacBook Pro, but work very very slowly if i try to put the client and the server on two computer that are not macbook pro. I have this problem only if i try to send a reference of the client to the server with invocation of a remote method.
This is my code
SERVER:
public class Server{
public static void main(String [] args){
try
{
Server_Impl server=new Server_Impl();
Registry reg=LocateRegistry.createRegistry(1099);
reg.bind("Server",server);
if(new Scanner(System.in).nextInt()==-1){
System.exit(0);
}
}
catch (RemoteException e){e.printStackTrace( );}
catch (AlreadyBoundException e) {e.printStackTrace( );}
}
}
CLIENT
public class Client{
public static Interfaccia_Server Server;
public static void main(String [] args){
try{
Registry reg=LocateRegistry.getRegistry("10.0.1.5",1099);
Server = (Interfaccia_Server) reg.lookup("Server");
Client_Impl c= new Client_Impl(Server);
Server.connect_client(c);
c.check_action();
}
catch(Exception e){
}
}
}
All of the code work, but very very slow if client and server are not on the same machine, or on a apple mac computer.
If i remove this line of code from the client all work very well anywhere, but i need the reference of the client in the server
Server.connect_client(c);
I have no idea about, please help me

Related

retrofit spring boot not responding

I have a server in spring boot, which is running on port 8080.
Now I'm trying to call rest api in my android application using retrofit2.
Here is what I have implemented:
final TextView textView=findViewById(R.id.t1);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://localhost:8080/")
.addConverterFactory(GsonConverterFactory.create())
.build();
JsonPlaceHolderApi jsonPlaceHolderApi = retrofit.create(JsonPlaceHolderApi.class);
Call<TC> call = jsonPlaceHolderApi.getPosts();
call.enqueue(new Callback<TC>() {
#Override
public void onResponse(Call<TC> call, Response<TC> response) {
textView.setText(response.toString());
if (!response.isSuccessful()) {
return;
}
TC posts = response.body();
textView.setText(posts.toString());
}
#Override
public void onFailure(Call<TC> call, Throwable t) {
}
});
I can surly say that, it's not working as my api is not even being called. As the hello world screen remains as it is.
And in my server I have logger, which doesn't log anything, so it doesn't get called.
Here is my CORS:
#Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
#Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("*")
.allowedOrigins("*");
}
};
}
The problem is with the word localhost.
As for debugging purpose I'm connecting the android device with my PC so my android device can't connect to localhost as it is just an alias of my IP address.
To resolve this, I opened up CMD and wrote ipconfig, by this command I can see all details related to IP.
And here it shows my IPv4 address as $.$.$.$. I just replaced the localhost with that $.$.$.$.
Now everything is working fine.
Any ideas how to make it work with Asp.net core. I just test it wih my local machine ip address and work perfectly.
Unfortunately, not the case with Asp.net core.
aAndroid + Retrofit + Asp.net API "java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."

How to stop WebApi project from Owin WebApp

I have a WebApi called MyWebApi project that run on port 42000 in debug mode.
I created a console application with Owin to host MyWebApi using the following technique:
static void Main(string[] args)
{
using (WebApp.Start<WebApi.Startup>("http://localhost:9000/"))
{
Console.WriteLine("Server is running...");
Console.WriteLine("Press Enter key to stop it.");
Console.ReadKey();
}
Console.WriteLine("Server is shutting down...");
}
Everything work fine. I can get and post data from both ports 9000 and 42000.
After I stop my console, I still can post and get data from port 42000.
Are there any way to stop the MyWebApi just like we stop debugging directly from WepApi project?
thanks,
Austin
Try disposing your webApp:
using (var _webApp=WebApp.Start<WebApi.Startup>("http://localhost:9000/"))
{
Console.WriteLine("Server is running...");
Console.WriteLine("Press Enter key to stop it.");
Console.ReadKey();
_webApp.Dispose();// Add this
}
Console.WriteLine("Server is shutting down...");
public class Startup
{
private static readonly IUnityContainer _container = UnityHelpers.GetConfiguredContainer();
public static void StartServer()
{
string baseAddress = "http://localhost:8081/";
var startup = _container.Resolve<Startup>();
IDisposable webApplication = WebApp.Start(baseAddress, startup.Configuration);
try
{
Console.WriteLine("Started...");
Console.ReadKey();
}
finally
{
webApplication.Dispose();
}
}
}
SELF HOST WEBAPI WITH OWIN AND UNITY
webApplication.Dispose(); - stop webapi server

WebSocket on Wildfly 10 not working on Windows 10

I have a problem with WebSocket to work on Wildfly 10, every time that I try send a message from Wildfly to the browser the connection is closed showing an 1006 code.
#ServerEndpoint("/debugger")
public class SocketDebugger {
#OnOpen
public void onConnect(Session session) {
session.setMaxIdleTimeout(0);
try {
session.getBasicRemote().sendText("Teste");
} catch (IOException e) {
e.printStackTrace();
}
}
}
This error does not occur if I open a WebSocket connection on a machine with Windows 7 or lower. Also on my machine with Windows 10, when I create a project using NodeJS Socket.IO communication works standard, this error happens with Java projects.
I found the solution, Kaspersky had a block to the WebSocket communication.

Bosh over https using smack

I am trying to have create Bosh connection to openfire over https. I have tried using the BoshConfiguration with hhtps argument as true. But connection times out at remote server.
Anyone has any working example of Bosh over https in smack ?
I´ve faced the same problem. I could make the connection and login by changing JBosh library, since the HttpClient usage there does not consider a SSL Context.
I followed the approach used in http://www.java-samples.com/showtutorial.php?tutorialid=211 for this, with some modification in subscribe() method, returning the SSLContext and using in XLightWebSender.java init() method, like this:
public void init(final BOSHClientConfig session) {
lock.lock();
try {
cfg = session;
SSLContext context = null;
try {
context = this.subscribe();
} catch (Exception e) {
e.printStackTrace();
}
client = new HttpClient(context);
} finally {
lock.unlock();
}
}
PS: I´m still testing and don´t guarantee that this work-around works fine for long living connections.

Spring RMI non-JRMP server at remote endpoint

I'm running the following code:
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class RmiClient {
public static void main(String args[]) {
try {
String hostName = "hostnameChangedForOnlineReference";
Registry registry = LocateRegistry.getRegistry(hostName, 1099);
String[] names = registry.list();
for (String name : names) {
System.out.println(name);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
And getting the following error
java.rmi.ConnectIOException: non-JRMP server at remote endpoint
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:230)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.list(Unknown Source)
at RmiClient.main(RmiClient.java:9)
Yet other RMI code running on my machine connects to this same service just fine.
Can anyone suggest a path of investigation for this inconsistent behaviour on my machine?
(When I do rmi in spring I get exactly the same error, but this is an easier set of code to digest).
non-JRMP server at remote endpoint
means that it turns out turning on SSL was required.

Resources