I have written code for a tcp (SSL) server which receives client connections and distributes data to the clients. the server GUI is based on JavaFX. When i run the server software from within Net Beans or Eclipse it works fine, receives client connections and sends and receives data. But when i compile the code into an executable Jar the server does not receive connections and client code throws: Connection refused exception.
I have tried pinging the server and it seems the server does not listen to the specific port when it is run from the executable Jar but DOES when run from within the IDE.
to be honest , I have no idea what could be causing this behavior. would appreciate any insights , suggestions or leads into how to fix this issue. I dont think the specific code is relevant but if somone thinks it is i will post the server code.
Well, turns out the problem was that the relevant keystores were not being loaded right. They were being loaded as FileInputStreams which will not work when embedded inside a Jar file.
I reverted them to being loaded as InputStreams , which work just as well with the SSL context and everything seems to be working right now.
Thanks a bunch for all the suggestions they defiantly helped me eliminate things along the way.
Related
Generally we learnt through http connection client server connection happens,
My question is we deploy .class files in server say tomcat, do
tomcat understands .class files?
As I learnt .class files are byte code understood by jvm means as per my understanding everything(protocal-webserver-javacode ) first converts to binary code and then communicates with each other,correct me if I'm wrong if so then please explain me in details and links to read more on it ?
Is it possible to run class file which is on different system?
For instance,
I have 2 machines (server and client) and there are 2 java class files SocketServer.class and SocketClient.class in respective machines.
I need to run SocketClient.class from server machine to make connection establish between server and client. (Note: I should not run SocketClient.class manually)
Please advice?
Thanks in advance.
-Sithik
It is my understanding that the client generally makes the connection to the server to access resources on the server. In the past I have used an API to access resources on the server. Essentially I am not running the classes from the server directly I am using the API as a form of abstraction in order to handle the communication between the resources on the client side and server side.
I also mainly implement the Factory Design Pattern which may help you here.
http://howtodoinjava.com/2012/10/23/implementing-factory-design-pattern-in-java/
Ultimately your application should make requests of a server first and once a connection is established then the server will provide a response.
It seems that with the latest Java update, 1.7.0u45, my JNLP application that is supposed to connect to a server is instead forced to try and connect to localhost for some reason that I cannot quite seem to figure out.
I know that some other changes have been made, such as requiring the Permissions attribute in the manifest and some such things, which I'm currently trying to figure out a reasonable way to comply to, but I cannot find anything that ought to cause this behavior.
My code just does an ordinary Socket.connect call to a specific server, but what happens is that the connection is instead made to localhost. This only happens when the code is running in the JNLP client; not when I run it "manually" by starting the VM on it.
Does anyone know why this is?
At last, I managed to figure out what was happening. It was not, in fact, that connections as such were being redirected, but rather that the JNLP client has started blocking JNLP files that are not signed from setting system properties with certain names. Particularly, only properties whose names begin with jnlp are, it seems, guaranteed to be configurable by unsigned JNLP files.
The problem, therefore, was that I specified what server to connect to via a system property whose name did not begin with jnlp, and it then being blocked (since my JNLP file isn't signed) led to my program using its default server specification instead, being localhost.
I am trying to achieve a TCP connection between a JavaScript client and a java server. (implementation must be this way I cannot swap to node for the server for example ).
Web sockets implmentation in java looked very complicated. I had a look at Jetty and JWebSocket and was quickly scared off. I have no idea what is going on in the source for them. – So I didn’t have much luck implementing a server using them.
So then I looked for websocket alternatives.
I noticed SocketBridge, It seems very straight forwards and offers exactly what I need for my project so I downloaded that.
I created a simple java server that just prints what I receives and sends a string as bytes back. I used the prebuilt JavaSocketBridge and modified the index.html to point to my server. My server recived the message but nothing showed up on the client.
function run(){
socket_connect('localhost', 31113);
socket_send("Hello from JavaSocketBridge applet");
}
I then decided to build the JavaSocketBridge to see if I could debug the read methods. However my build of JavaSocketBridge refuses to connect with the error.
Java Socket Bridge ERROR: Could not connect to localhost on port 31113
Access denied (“java.net.SocketPermission” “127.0.0.1:31113” “connect,resolve” )
(This was in chrome but it happens in firefox too)
So my questions:
Why does my build get a socket permission error?
Why does the client not receive anything even though the example does from google.com:80?
Notes.
My server appears to be working fine. (I have used a simple java client to test it.
I have used java 1.6 and 1.7 to build the JavaSocketBridge)
I have included C:\Program Files\Java\jre7\lib\plugin.jar
My System is Win7 64 and java SDK / JRE is up to date
Edit. Ive gone back to jetty and got a client/server working, however I will monitor this question.
I'm making a simple chat client using OpenFire 3.7.1 and SMACK 3.2.2 on a localhost. I wish to know if it is possible to establish 2 connection to the server from the same machine.
Illustration: I have made a working client for simple exchange of messages. I'll run two jar files of the client (containing a login prompt), I'll make two different logins for two different users.
Now I tried doing that, but got Stream:error which I know refers to connection too many times or 2 users or something like that. I don't know the exact details about that error. Your help would be appreciated. Thank you.
Yes, you can even do this from the same application. There are integration tests run from Smack that do this all the time.
You only have to make sure to log in with different JID's.