How do I use socket.io-java-client java - java

I designed a chat application to support a store. The chat is very important for the store because it sells and trade items, so there's lot of communication. There's two end-points, the website that contains the chat as an icon and the help desk which is accessed through a web page.
I designed a chat using the socket.io library. The system is basically a web chat. I want to make an android application that will perform the help desk tasks. Using the the javascript library was a piece of cake but I am having trouble using a java package . I using Netbeans as IDE I created a project set up as java Maven. I am just testing out and afterwards I want to build an Android App as said before.
I wrote a code like this to try to connect. I add console.log on the server to check if it was connecting but nothing happens.
io.socket.client.Socket socket = IO.socket("https://example.com.br:3009");
JSONObject obj = new JSONObject();
obj.put("id", "null");
obj.put("nome", "android");
IO.Options ops = new IO.Options();
ops.secure = true;
ops.reconnection = true;
socket.on(io.socket.client.Socket.EVENT_CONNECT, new Emitter.Listener(){
#Override
public void call(Object... os) {
socket.emit("join", obj);
System.out.println("executou");
}
});
socket.connect();
What am I doing wrong?

It turned out that I had okhttp as a dependency and the version that was using 3.9.1 generates this issue. I changed it to 3.4.1 on pom.xml and it worked. I was getting exception on the Netbeans Window but I was ignoring it "okHttp3 java.lang.NoSuchMethodError: No virtual method setCallWebSocket". I thought it was a minor issue.

Related

how to fetch streams and display its name on console using server side API

I want to fetch all the streams of a project area and display their names on console using server side API.
IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(teamRepository);
IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
wsSearchCriteria.setPartialOwnerNameIgnoreCase(projectAreaName);
List <iworkspacehandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, monitor);
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandles.get(0),monitor);
String obj="";
obj=workspaceConnection.getName();
System.out.println(obj);
this code does the task on client side.
How this can be done using server side API?
SDK (used server side or like plugin on client) and plain API are really different. Plain API are plain java classes, but with SDK you have to create osgi plugins to the platform to be deployed on server. You can follow this POT: https://jazz.net/library/article/1000 that is for 4.0.x version but still valid.

Receiving native messages from Chrome in Java

I am trying to get native messaging between a chrome extension and a Java program to work.
After some struggling I now can open my Java program with:
var port = chrome.extension.connectNative('fbehost');
port.postMessage({ text: "Hello, my_application" });
But I don't know how I can read the message send from my extension. I created a program which opens a simple JFrame with a textarea. As it says in the documentation that native messaging communicates with stdin and stdout, I tried to get the message with:
while(true) {
try {
input=br.readLine();
tf.setAreaText(input);
} catch(Exception e) {
}
}
Also tried it with:
System.in.read()
The jar gets executed but the textarea stays empty. I can't find any information on the internet how to get the data in Java. Can you help me?
I haven't been able to get any native messaging to work in Google Chrome recently. I remember reading somewhere that a semi-recent update appeared to prevent compatibility between Java and Chrome for native messaging. Best of luck.

What is the way to create socket on android platform from javascript?

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.

NetBeans 5.5.1 Webstart RMI client can't connect after Java Update 25

Having called into the NetBeans library with :-
try {
Object[] argss = new String[] {"--branding", "assetwatch_platform"};
Class c = loader.loadClass("org.netbeans.Main");
Method m = c.getMethod("main", new Class[] { String[].class });
m.invoke(null, new Object[] {argss});
} catch (Exception ex) {
ex.printStackTrace();
}
}
NetBeans creates the platform window but fails to pass control onto user code and cannot connect over the RMI port 80. There is nothing in the webstart client logs. I have read all the questions about the class loader and have applied the workarounds to no effect. I have tried getting hold of the source for 5.5.1 but the CVS server no longer responds. Any ideas?
I 'bit-the-bullet' and used the ant build here [Netbeans platform][1]https://platform.netbeans.org/tutorials/nbm-ant.html#rcp to get the latest platform. After some 'frigging in the rigging' the web-start application was resurrected with very little change to the source or the application. This has to be testament to the quality of the NetBeans framework. The Web Browser module is still not adequate for modern webapps and I have to find a way of disabling modules but generally a cloud has lifted from above me.

Reporting Services WS from Java - Getting (401)Unauthorized

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.

Categories

Resources