I am trying to make tic tac toe using websockets running on glassfish. I've download this example form git. Firstly, I want to test it, so I run it as a normal java process on my machine. I also made a tiny change to the tictacto.js
if (typeof MozWebSocket != "undefined") { // (window.MozWebSocket)
appType = "Mozilla";
} else if (window.WebSocket) {
appType = "Chrome";
} else {
alert('ERROR: This browser does not support WebSockets');
}
and then
if (appType == "Mozilla") {
ws = new MozWebSocket(WEBSOCKET_URL);
//alert('MozWebSocket');
} else {
ws = new WebSocket(WEBSOCKET_URL);
//alert('WebSocket');
}
When I open the test page with FF 10.0 the event onclose is only invoked and I get the status "The WebSocket Connection Has Been Closed." then I open the test page with Chrome 17.0.963.46 m. The status is also "The WebSocket...." but server throws an exception.
run:
TicTacToe Server: Listening on port 9000
java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:218)
at sun.nio.ch.IOUtil.read(IOUtil.java:186)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:359)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:323)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:282)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:202)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
What is the cause? I though about a few possilbe issues:
I use Netty 3.2.6.Final from JBoss repository. It could use different standard of websockets than the browsers.
running it as a java process on my machine istead as a webserver. But Netty doesn't have any dependencies that would require it.
Wrong locations. var WEBSOCKET_URL = "ws://localhost:9000/websocket"; and html location is C:...web\kolo\src\main\webapp\t.html
I am using Netbeans 7.1 and glassfish 3.1
Fixed project can be found https://github.com/lukasz-madon/Tic-Tac-Toe-with-WebSocket
I could be the web socket version. Here's a table of web socket versions and which browser supports which.
From memory, 3.2.6 only supported HyBi-00.
Try Netty 3.3. It supports a number of versions.
Related
I've just checked out the Eclipse Milo Project (https://projects.eclipse.org/proposals/milo), which seems to be a great project for an "open" OPC UA Client/Server even with the implemented OPC Stack. The project on github (https://github.com/eclipse/milo) contains a Hello World example, where an OPC Server is started and an example node is sent and received from the client. Everything works fine!
But in my next step, I wanted to check if the server is configured correctly. Therefore I've installed Matrikon Explorer, but the Explorer is stating out "No OPC servers installed on this machine" right after start (while the hello world example with a running OPC Server is running of course).
Also checked, if SAP Plant Connectivity is recognizing the OPC Server (which is the goal of my project) -> "Found no OPC Server on your system/localhost"
Where is my problem, what do I have to do, to install and configure the Server correctly?
Here's the Hello World Example:
public static void main(String[] args) throws Exception {
// Start server
int port = 12686;
String serverName = "test-server";
OpcUaServerConfig serverConfig = OpcUaServerConfig.builder()
.setBindPort(port)
.setCertificateManager(new DefaultCertificateManager())
.setCertificateValidator(new DefaultCertificateValidator(createTempDir()))
.setServerName(serverName)
.setUserTokenPolicies(singletonList(USER_TOKEN_POLICY_ANONYMOUS))
.build();
OpcUaServer server = new OpcUaServer(serverConfig);
server.getNamespaceManager().registerAndAdd(
"urn:eclipse:milo:opcua:test-namespace",
idx -> new HelloNamespace());
server.startup();
while(true){
System.out.println("server running");
}
}
Matrikon Explorer is an OPC-COM/DA client, and is probably interrogating the OPC Enum service in order to find registered COM clients.
OPC-UA is an entirely different, platform independent, technology. The concept of registration still exists, but it's not forced by default.
Try using an OPC-UA client like UaExpert to connect. Given the configuration you've copied, you'll want to point UaExpert at the endpoint URL opc.tcp://localhost:12686/test-server
I'm guessing there will be an issue once you connect with the partially implemented "hello world" namespace. I'll make sure we get a fully usable namespace example committed this week.
You can also look at the OpcUaClientIT integration test class for various client functionality and another example of setting up a server.
I've created a basic java EE 7 chat application - with Intellij Ultimate 14 - that lets users send messages and receive messages (using sessions, no room, no user identification).
I've tried the application by itself on a glassfish 4.1 server on windows 8.1 : it works perfectly.
Now I'm trying to run it in an ubuntu 14.04 server hosted in virtualbox (same glassfish and java ee version), this is so that I can later work on clustering the application.
When I install the application on the ubuntu server, using the web based interface (that I access from the windows host), I can load the application in a chrome, but the websocket doesn't seem to connect properly and therefore I cannot send any message at all.
By the way, I've tried connecting the websocket on the glassfish installed on the windows and it works fine.
Here is the html side of the app connecting the websocket to the server :
var host = "ws://" + document.location.host + "/GlassFish7_war/test";
wsocket = new WebSocket(host);
wsocket.onmessage = onMessage; // the function that displays received messages
and here is the relevant part of the server accepting the socket :
#ServerEndpoint("/test")
public class MyEndPoint {
#OnOpen
public void openConnection(Session session) {
session.getBasicRemote().sendText("hello there !");
// [...]
}
}
you guessed it : I never receive the "hello there !" message on the client side.
I think the problem might come from the configuration of the virtualbox network, yet I can't seem to figure out what to do about it. Currently I have a bridged and a NAT adapter.
Any help would be greatly appreciated !
Thanks a lot !
I am making an application using phonejs. I want to create socket to get live data from server to display. I found HTML5 WebSocket working fine with web browser but not with mobile device. I used phonegap-build from http://build.phonegap.com to build application.
I tried to add 3rd party plugin(com.ququplay.websocket.websocket) of phonegap and run application with android mobile device but the application got crashed.
Here is how I work with WebSocket:
var initSocket = function(){
try{
var socket = new WebSocket(websocket.host);
socket.onopen = function(msg){ console.log("Welcome - Live Data"); };
socket.onmessage = function(msg){
console.log('-------- live data ------');
// Here some work
}
}
catch(ex){ console.log(ex); }
};
Is there any other way to make socket run on android phone from javascript? Or any connector that can create socket on android phone from javascript?
I created cordova project with android platform and added WebSocket plugin from https://github.com/knowledgecode/WebSocket-for-Android.
I merged my application code in assets. This plugin handled socket related operations without need of changing my WebSocket related code.
I've searched through the site and haven't quite found a post that answers my problem.
I wrote a desktop application (Java/swing/JDBC) to connect to a local database via JDBC. This database is hosted on an IBM i-series (AS400) (though I'm quite certain this isn't an as400-only problem) and is only available on the internal network. I'm working on translating that application into an android app to be used onside in the warehouse via wireless connection.
I have my JDBC connection in it's own thread. The app asks the user for username/password before attempting a connection. The connection fails every time with the same message: java.sql.SQLException: The application requester cannot establish the connection. (No route to host)
Here is the offending code:
try
{
// Use the AS400 driver.
DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
// Now connect
connection = DriverManager.getConnection(
"jdbc:as400://" + IP_ADDRESS + "/" + SCHEMA +
";naming=sql;errors=full",
USER_ID, PASSWORD);
System.out.println("Connection established using the AS400 driver(s)");
}
catch(Exception as400)
{
String message = "Error setting driver and connection using\n "
+ "the AS400 drivers. The error message is as follows:\n "
+ as400.getMessage();
System.out.println(message);
throw new Exception(message);
}
It registers the driver then hits No route to host, pauses for a second, then throws an error, completely stalling the device instead of letting my error handler safely close the app.
I have double (triple) checked to ensure the credentials are correctly passed and the IP and schema are both correctly set. This code is a direct copy of my desktop code. The only difference is I use a jar optimized for android instead of the desktop. The jar simply contains a translation layer between native AS400 code and Java, but works the same as any SQL jar.
This is our primary database server used throughout the entire company. It is always available and SQL is enabled on it. I am testing this using a physical android device (not an emulated one) and it is connected to our internal wireless network.
Any suggestions on how to fix this or even a direction to look in? Why is there such a difference between the desktop and my android despite both using JDBC? Do I need to do something special for address resolution or something similar? Google-fu is failing me badly. Thanks for your help!
It's not uncommon for wireless traffic to be restricted due to corporate security policies.
Verify that you can connect to DRDA (tcp port 446) on the IBM i from the device on the wireless network.
See TCP/IP Ports Required for iSeries Access for Windows for more information.
JTOpen/Toolbox has a proxy mode if security requirements prevent allowing direct access to the IBM i.
The lightweight version of the JTOpen/Toolbox jar's are also more suited to installation in a cpu and memory restricted environment such as an Android device.
The full JTOpen/Toolbox can be run as a proxy server as follows:
java -cp jt400.jar com.ibm.as400.access.ProxyServer -verbose -port 3470
Add the proxy server option to your connection string:
jdbc:as400:<url>;proxy server=<proxy server address:port>
We're writing a web application that is trying to replace all ReportManager functionality using calls to Reporting Services SOAP API.
We started working with SSRS 2008 and had our Java code working correctly. We've since had to downgrade to SSRS 2005 and now we're having problems connecting to the Server to get the list of reports available.
We make the following call:
catalog = _reportingService.listChildren(_reportCredentials.getFolder(), false);
which returns an exception - (401)Unauthorized
_reportCredentials just holds information from a properties file (like the folder to use, the username and password, etc.). _reportService is defined as:
private ReportingService2005Soap _reportingService;
...
_reportingServiceLocator = new ReportingService2005Locator();
_reportingServiceLocator.setReportingService2005SoapEndpointAddress(soapURL);
try {
_reportingService = _reportingServiceLocator.getReportingService2005Soap();
} catch (Exception e) {
throw new ReportServicesException("Could not retrieve SOAP Reporting Service.");
}
I can also connect to ReportManager as the user/password we're connecting with in the code.
All of the 'documentation' I can find is just .NET code that doesn't seem to apply to the Java code. Has anybody experienced problems like this, or know of a good resource for Java developers using these services?
We traced the problem back to having SSRS 2005 installed on Windows Server 2008. Following the steps here: http://www.omegaprojex.com/index.php/2008/10/10/ssrs-2005-on-windows-server-2008/ fixed our problem.