running local host openfire and smack client library andorid - java

I installed openfire local server on my laptop and using smack library as xmpp client. I followed this and
this.
After running code I dont see any exception and I don't understand if my user is connected to server. Is there any way to check connection .
Code for making connection to server
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setUsernameAndPassword(loginUser, passwordUser);
config.setServiceName(ConnectXmpp.DOMAIN);
config.setHost(ConnectXmpp.DOMAIN);
config.setPort(5222);
config.setDebuggerEnabled(true);
connection = new XMPPTCPConnection(config.build());
Log.e("connection",""+connection);//this line to check connection
XMPPConnectionListener connectionListener = new XMPPConnectionListener();
connection.addConnectionListener(connectionListener);
I added user at server and using that username for login at app side.
please guide me where i can check incoming messages fromclient to server , im using embedded database.

Check your callback listener; it will return the connection object.

Related

How to connect to RedisJson with JReJSON package in java?

Recently, I started working with RedisJson with node, but I also have to work with Java version of it.
I'm trying to create a connection as it is mentioned in this github repo: https://github.com/RedisJSON/JRedisJSON
The repo shows connection with "localhost", but I want to connect to my remote Redis server instance which has the URL like redis://:password#host:port.
I'm trying to pass the host and port like the following:
JReJSON jsonClient = new JReJSON("redis://:password#host", port);
But I'm getting the following error saying 'Failed to create socket' and 'UnknownHostException':
But, I'm able to connect to the same host from command line.
Could someone point out what is the issue or what is the actual way to connect to remote instance with RedisJSON in java?
Note: I'm using Jedis - jedis-4.3.1.jar and Rejson - jrejson-1.4.0.jar
Part 1: About the library
Check what the JRedisJSON home page says:
As of Jedis 4.0.0 this library is deprecated.
Since Jedis 4.0.0, you won't need jrejson/JRedisJSON separately. As you're already using jedis-4.3.1, you're good to go only with Jedis.
Check their quick start.
Part 2: About the constructor
You want to create client object from host, post and password. Check following two constructors:
new JedisPooled("redis://:password#host:port")
new JedisPooled(host, port, user, password) -> new JedisPooled(host, port, null, password)

Java client connectivity issue - OPC DA

Recent Microsoft patch has broken our Java client connectivity to OPC server. Microsoft raised Authentication level to Packet Integrity. we are using Utgard java OPC library to connect to OPC server which internally uses Jinterop java based COM library. with the patch Our client is not able to add subscription groups to listen to the data changes on the OPC server. We couldn't find where in the library the authentication level is configured. if we can configure it ti DEFAULT the issue will be resolved.
Please let me know if you have any pointers on this.
JISession session = JISession.createSession(ipAddress,userName,pasword);
JIComServer comServer = new JIComServer(JIClassId.valueOf(classId), address, session);
IJIComObject instance = comServer.createInstance();
IJIComObject opcServer = new OPCServer(instance);
//after we will create access base groups and add them to the server, during attaching handler it is failing.
ERROR
*JIException: The RPC server is unavailable. Please check if the COM server is up and running and that route to the COM Server is accessible (A simple "Ping" to the Server machine would do). Also please confirm if the Windows Firewall is not blocking DCOM access. [0x800706BA]
at org.jinterop.dcom.core.JIComServer.call(JIComServer.java:1004) at org.jinterop.dcom.core.JIComServer.call(JIComServer.java:951) at org.jinterop.dcom.core.JIComObjectImpl.call(JIComObjectImpl.java:293) at org.jinterop.dcom.core.JIComObjectImpl.call(JIComObjectImpl.java:159) at org.jinterop.dcom.core.JIFrameworkHelper.attachEventHandler(JIFrameworkHelper.java:285) at org.openscada.opc.dcom.da.impl.OPCGroupStateMgt.attach(OPCGroupStateMgt.java:179)
*

Java RMI cannot connect to server via WAN while it works in LAN

I'm working on a project using Java RMI and with a client-server implementation.
On the server side, this is how I initialize my server:
final String url = "localhost";
final int port = 8090;
LocateRegistry.createRegistry(port);
IServerGame serverGame = new ServerGame();
Naming.rebind("//"+url+":"+port+"/undercover", serverGame);
System.out.println("Server running at //" + url + ":" + port + "/undercover")
Undercover is the name of my application. We chose to use the port 8090
arbitrarily.
Now, here is how I initialize the connection client-side:
try {
server = (IServerGame) Naming.lookup("//"+address+":8090/undercover");
System.out.println("Connected to server " + address + ".");
} catch (Exception e) {
System.out.println("Connection failed.");
e.printStackTrace();
}
address is a string in the parameter of the method which initializes the connection and is the IP of the server. We ask the client to enter this IP to allow us to connect to different servers if we want.
When I run my application in local, whether I use localhost or my private IP 192.168.x.x as address, everything works fine. The client connects to the server and I can use the application. The problem is that when I want to use the application via WAN, sending the client to a friend and starting the server on my local machine, it doesn't work anymore. I get this error:
java.rmi.ConnectException: Connection refused to host: (private IP of host machine); nested exception is:
java.net.ConnectException: Connection timed out: connect
I've already checked a lot of posts in StackOverflow with the exact same problem and the usual answer is to either set the SystemProperty(java.rmi.server.hostname,"192.168.x.x") or do it via the -Djava.rmi.server.hostname in command line. I'm using Gradle to compile. I run the application via the run task. The client is a basic fx application too. None of this works unfortunately. I've also tried to open the port 8090 in my firewall but it doesn't solve the problem either.
Now maybe I'm doing this wrong. I've also tried to replace my private IP 192.168.x.x, which is IPv4 that I found via ipconfig in the command shell, with my public IP 79.95.x.x. But, again, it doesn't work.
I tried adding the SystemProperty(java.rmi.server.hostname,"192.168.x.x") like the first line of code that appears in the server code I showed you above.
I'm connected to internet via 4G. I don't have a box connection, so I can't really go to the box settings to allow certain ports, if that's ever a thing that could fix the issue.
EDIT :
So i've tried to switch from naming implementation in server-side to Registry implementation as it was suggested bellow but it didn't make any difference. As i thought it could be just a connection problem, i asked a friend to ping the server with telnet on the port 8090 and in fact it didn't work. He ran telnet [domain name or ip] [port] and the error was :
Unable to connect to remote host: Connection timed out
So the problem is that the external clients cannot reach my server or connect to the port. As i'm using 4G as internet connection as i mentioned above, any idea on how i could make the port reachable ?
Try using class java.rmi.registry.Registry rather than class java.rmi.Naming.
On the server side:
final int port = 8090;
Registry registry = LocateRegistry.createRegistry(port);
ServerGame serverGame = new ServerGame();
IServerGame stub = (IServerGame) UnicastRemoteObject.exportObject(serverGame, 0);
registry.bind("undercover", stub);
On the client side:
Registry registry = LocateRegistry.getRegistry("server host name or IP", 8090);
IServerGame serverGame = (IServerGame) registry.lookup("undercover");

Connecting to an FTP server via a proxy using Apache FTPClient

Using the Apache FTPClient, i can usually connect using the following statements:
FTPClient client = new FTPClient();
client.connect("ftp.myhost.com");
client.login("myUsername", "myPassword");
client.changeWorkingDirectory("/fileFeed");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
client.setFileTransferMode(FTPClient.BLOCK_TRANSFER_MODE);
The above works fine but now i am to connect to the FTP site, i have to use a proxy server. The instructions i got is that i should connect to the proxy server and specify the actual ftp server in the username. So to log on i would use the following details to connect:
ftp ftp.myProxyServer.com
username myUsername#ftp.myhost.com
password myPassword
I tried connecting directly using the command prompt and i can connect to the ftp.myProxyServer.com host and it does forward me to the intended ftp site if i specify myUsername#ftp.myhost.com as the host username. The problem is that the above type of connection is not accepted in Java using Apache FTPClient:
FTPClient client = new FTPClient();
client.connect("ftp.myProxyServer.com");
client.login("myUsername#ftp.myhost.com", "myPassword");
client.changeWorkingDirectory("/fileFeed");
client.setFileType(FTPClient.BINARY_FILE_TYPE);
client.setFileTransferMode(FTPClient.BLOCK_TRANSFER_MODE);
Is there anything i am missing or would the above not work? I tried a direct connection and that works fine.
The FTPClient usually is in active ftp mode, and in case your proxy is not able to initiate a tcp connection back to your client computer (for firewall/DMZ reasons) then you have to switch to passive mode:
FTPClient client = new FTPClient();
client.connect("ftp.myProxyServer.com");
client.login("myUsername#ftp.myhost.com", "myPassword");
client.enterLocalPassiveMode(); //switch from active to passive
client.changeWorkingDirectory("/fileFeed");
...
(Furthermore I would like to recommend to always check the return codes of the method calls, but probably they are ommitted for sake of clarity)
Sorry for the late attempt to answer your question...

not able to connect to server on internet

I have a very simple client server code written java(server listens on some port and client connects to server port and after connection is established, client ip is displayed on server console). This program is working very well in intranet, but if client and server are on internet, my server cannot detect it.I have no firewall installed on my client and server and port forwarding is done on server(I can see it from canyouseeme.org).
Server is directly connected to modem along with other three computers(they are also connected to modem directly)
Please help me figure out why I am not able to detect client on internet.Thanks in advance.
Client code:
------------
String remoteIP = //remote ip
int port =1888;
try{
new Socket(remoteIp,port);
}catch(Exception e){
System.out.println(e.message());
}
Server code
-----------
ServerSocket serversocket = new ServerSocket(port);
Socket socket = serverSocket.accept();
displayIp(socket);
Check your proxy configurations on the client side, see http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
Which protocol do you use?

Categories