java - couldn't connect to socket (WSANOTINITIALISED, WSAStartup() has not been called) error while running program -


i have test class try connect open office.

import com.sun.star.bridge.xunourlresolver; import com.sun.star.comp.helper.bootstrap; import com.sun.star.lang.xmulticomponentfactory; import com.sun.star.lang.xmultiservicefactory; import com.sun.star.uno.unoruntime; import com.sun.star.uno.xcomponentcontext;  public class test {        xmultiservicefactory ooconnect() {          final string sconnectionstring = "uno:socket,host=localhost,port=8100;urp;staroffice.servicemanager";         // create initial component context         xcomponentcontext rcomponentcontext = null;         try {             rcomponentcontext = bootstrap                     .defaultbootstrap_initialcomponentcontext();         } catch (exception e2) {             // todo auto-generated catch block             e2.printstacktrace();         }          // retrieve servicemanager context         xmulticomponentfactory rservicemanager = rcomponentcontext                 .getservicemanager();          object objecturlresolver = null;         try {             objecturlresolver = rservicemanager.createinstancewithcontext(                     "com.sun.star.bridge.unourlresolver", rcomponentcontext);         } catch (exception e1) {             // todo auto-generated catch block             e1.printstacktrace();         }          // create new url resolver         xunourlresolver xurlresolver = (xunourlresolver) unoruntime                 .queryinterface(xunourlresolver.class, objecturlresolver);          xmultiservicefactory rofficeservicemanager = null;         try {             // resolve uno-url              system.out.println("block 3");             object objectinitial = xurlresolver.resolve(sconnectionstring);              rofficeservicemanager = (xmultiservicefactory) unoruntime                     .queryinterface(xmultiservicefactory.class, objectinitial);         } catch (exception e) {             e.printstacktrace();             return rofficeservicemanager;         }         return rofficeservicemanager;     }         public static void main (string [] args)      {         test test = new test();          xmultiservicefactory servicefactory = test.ooconnect();         if(servicefactory != null)         {             system.out.println("yeyeyeyey");         }     } } 

when try run code below exception.

com.sun.star.connection.noconnectexception: connector : couldn't connect socket (wsanotinitialised, wsastartup() has not been called)         @ com.sun.star.bridges.jni_uno.jni_proxy.dispatch_call(native method)         @ com.sun.star.bridges.jni_uno.jni_proxy.invoke(jni_proxy.java:171)         @ com.sun.proxy.$proxy3.resolve(unknown source)         @ test.ooconnect(test.java:47)         @ test.main(test.java:66) 

now understand why exception coming not getting solution on how resolve this.

on windows, winsock library must explicitly initialized process before can used. done using wsastartup() function, typically @ app startup. other platforms not require explicit socket library initialization before using socket api functions. uno framework should handling internally when running on windows. if not, consider framework bug, , should reported author accordingly. find unlikely uno not accounting this.

as workaround, have code use jna call wsastartup() manually before using uno.


Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -