Exception in connecting to socket

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Exception in connecting to socket

Anandha Kannan
Hi,

     I have an issue in resolving UNO URL after launching open office from
my applicaiton developing in Mac.
I start open office using socket as
"-accept=socket,host=localhost,port=2081;urp;"

This starts OO. Now to open a file passed from my application, I have the
following code,

rConnectionString = OUString::createFromAscii(
"uno:socket,host=localhost,port=2081;urp;StarOffice.ServiceManager");


        rComponentContext = defaultBootstrap_InitialComponentContext();



        rMultiComponentFactoryClient =
rComponentContext->getServiceManager();



        Reference< XInterface > xInterface =

        rMultiComponentFactoryClient->createInstanceWithContext(
OUString::createFromAscii( "com.sun.star.bridge.UnoUrlResolver" ),
rComponentContext );


        Reference< XUnoUrlResolver > resolver( xInterface, UNO_QUERY );


        // Resolves the component context from the office, on the uno URL
given by argv[1].

        try

        {

            xInterface = Reference< XInterface >( resolver->resolve(
rConnectionString ), UNO_QUERY );

        }

        catch ( Exception& e )

        {

            // THROWS EXCEPTION

            printf("Error: cannot establish a connection using '%s':\n
  %s\n",

                    OUStringToOString(rConnectionString,
RTL_TEXTENCODING_ASCII_US).getStr(),

                    OUStringToOString(e.Message,
RTL_TEXTENCODING_ASCII_US).getStr());

            exit(1);

        }


.......

.......


Here, I get exception saying *Connector: couldn't connect to socket
(Undefined error: 0). *What is the wrong with the UNO URL that causes this.


PS: After launching OOo, Using PortScan utility I can confirm that the port
has been opened.


Thanks in advance,

Anandh
Reply | Threaded
Open this post in threaded view
|

Re: Exception in connecting to socket

Ariel Constenla-Haile-2
Hi Anandh,

On Tue, Feb 26, 2013 at 10:58:43AM +0530, Anandha Kannan wrote:

> Hi,
>
>      I have an issue in resolving UNO URL after launching open office from
> my applicaiton developing in Mac.
> I start open office using socket as
> "-accept=socket,host=localhost,port=2081;urp;"
>
> This starts OO. Now to open a file passed from my application, I have the
> following code,
>
> rConnectionString = OUString::createFromAscii(
> "uno:socket,host=localhost,port=2081;urp;StarOffice.ServiceManager");
 

The connection URLs look fine (hint: use StarOffice.ComponentContext to
get the component context directly, no need to go through the service
manager.

And you'll find more useful a connection aware client, instead of using
the com.sun.star.bridge.UnoUrlResolver, see
http://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Example:_A_Connection_Aware_Client

Quoting from
http://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Importing_a_UNO_Object

The usage of the UnoUrlResolver has certain disadvantages. You cannot:

- be notified when the bridge terminates for whatever reasons
- close the underlying interprocess connection
- offer a local object as an initial object to the remote process

I've just uploaded an example (compiled only on Linux, later I'll test
it on Win and MacOS too):
http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/cppbindings/ConnectionAwareClient/

> Here, I get exception saying *Connector: couldn't connect to socket
> (Undefined error: 0). *What is the wrong with the UNO URL that causes this.
 
Do you try this code right after launching OpenOffice? May be the
application didn't start listening at that moment, you may have to wait
and give the application a little time to perform the start up actions.


> PS: After launching OOo, Using PortScan utility I can confirm that the port
> has been opened.

You can test with telnet:

telnet localhost 2081

You will get a request from the bridge counterpart (in URP protocol).
Also try with

netstat -ntlp | grep soffice


Look at the example I quoted above, at the beginning it has
a std::cin.get() in order to wait for the application to start, I'm sure
that if you remove this, the example will fail because the office
started quickly but isn't listening yet. This might be your problem too;
of course, in a real application you don't put cin.get()'s ;) you'll
need a better solution (the C++ binding provides multiplatform
facilities - osl::Condition, osl::Thread, etc.).


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Exception in connecting to socket

Anandha Kannan
Hi Ariel,

   Thanks for the reply. I tried with modifying my code to wait till, OO
stats. But still, am ending with same exception.
To check whether the port has been opened in listening mode, I got the
following result for telnet and netstat (no listing of this port in netstat)

admin$ telnet localhost 2081
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
e??'com.sun.star.bridge.XProtocolPropertiesUrpProtocolProperties.UrpProtocolPropertiesTidݓ??

admin$ netstat -ntpl | grep soffice
netstat: l: unknown or uninstrumented protocol
admin$ netstat -a | grep soffice
admin$

But using lsof i could get the required information and can confirm that
the port 2081 in my case, is being used by soffice and running in listening
mode.
admin$ lsof -i :2081
COMMAND  PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
soffice 5150 admin   15u  IPv4 0xffffff8015034320      0t0  TCP
localhost:kme-trap-port (LISTEN)

Also when i try to run your sample application, I get error,
"OpenOffice.org quit unexpectedly" and doesn't launch the process. Let me
know if you need more details on it.

Thanks,
Anandh

On Tue, Feb 26, 2013 at 6:24 PM, Ariel Constenla-Haile
<[hidden email]>wrote:

> Hi Anandh,
>
> On Tue, Feb 26, 2013 at 10:58:43AM +0530, Anandha Kannan wrote:
> > Hi,
> >
> >      I have an issue in resolving UNO URL after launching open office
> from
> > my applicaiton developing in Mac.
> > I start open office using socket as
> > "-accept=socket,host=localhost,port=2081;urp;"
> >
> > This starts OO. Now to open a file passed from my application, I have the
> > following code,
> >
> > rConnectionString = OUString::createFromAscii(
> > "uno:socket,host=localhost,port=2081;urp;StarOffice.ServiceManager");
>
>
> The connection URLs look fine (hint: use StarOffice.ComponentContext to
> get the component context directly, no need to go through the service
> manager.
>
> And you'll find more useful a connection aware client, instead of using
> the com.sun.star.bridge.UnoUrlResolver, see
>
> http://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Example:_A_Connection_Aware_Client
>
> Quoting from
>
> http://wiki.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Importing_a_UNO_Object
>
> The usage of the UnoUrlResolver has certain disadvantages. You cannot:
>
> - be notified when the bridge terminates for whatever reasons
> - close the underlying interprocess connection
> - offer a local object as an initial object to the remote process
>
> I've just uploaded an example (compiled only on Linux, later I'll test
> it on Win and MacOS too):
>
> http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/cppbindings/ConnectionAwareClient/
>
> > Here, I get exception saying *Connector: couldn't connect to socket
> > (Undefined error: 0). *What is the wrong with the UNO URL that causes
> this.
>
> Do you try this code right after launching OpenOffice? May be the
> application didn't start listening at that moment, you may have to wait
> and give the application a little time to perform the start up actions.
>
>
> > PS: After launching OOo, Using PortScan utility I can confirm that the
> port
> > has been opened.
>
> You can test with telnet:
>
> telnet localhost 2081
>
> You will get a request from the bridge counterpart (in URP protocol).
> Also try with
>
> netstat -ntlp | grep soffice
>
>
> Look at the example I quoted above, at the beginning it has
> a std::cin.get() in order to wait for the application to start, I'm sure
> that if you remove this, the example will fail because the office
> started quickly but isn't listening yet. This might be your problem too;
> of course, in a real application you don't put cin.get()'s ;) you'll
> need a better solution (the C++ binding provides multiplatform
> facilities - osl::Condition, osl::Thread, etc.).
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
>
Reply | Threaded
Open this post in threaded view
|

Re: Exception in connecting to socket

Ariel Constenla-Haile-2
Hi Anandha,

On Wed, Feb 27, 2013 at 01:01:24PM +0530, Anandha Kannan wrote:
> Hi Ariel,
>
>    Thanks for the reply. I tried with modifying my code to wait till, OO
> stats. But still, am ending with same exception.

Did you wait until you checked that AOO was listening on the port?
For now, just for testing purpose, you can put a cin.get(), and wait
until you are sure that AOO is listening, then press ENTER to continue
with your code.

> To check whether the port has been opened in listening mode, I got the
> following result for telnet and netstat (no listing of this port in netstat)
>
> admin$ telnet localhost 2081
> Trying ::1...
> telnet: connect to address ::1: Connection refused
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
> e??'com.sun.star.bridge.XProtocolPropertiesUrpProtocolProperties.UrpProtocolPropertiesTidݓ??
This is ok, it's the expected result.

> admin$ netstat -ntpl | grep soffice
> netstat: l: unknown or uninstrumented protocol

Seems MacOS uses the FreeBSD implementation, which does not support the
same options as in Linux.

> Also when i try to run your sample application, I get error,
> "OpenOffice.org quit unexpectedly" and doesn't launch the process.

Strange. I've just tested it, and works as expected:
http://people.apache.org/~arielch/images/connaware1.png
http://people.apache.org/~arielch/images/connaware2.png

Please try putting a cin.get() in your code, and press Enter to continue
only after you check that AOO is already listening. If after that you
can connect, then it is a timing issue.


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Exception in connecting to socket

Anandha Kannan
Hi Ariel,

        Thanks for the input. But i tried my code with cin.get() and ENTERED only after confirming that the port is listening  (using lsof -i :2081). Do u think there could be any other possible reason for this issue?!

Thanks for ur guidance,
Anandh

Sent from my iPhone

On 27 Feb 2013, at 07:07 PM, Ariel Constenla-Haile <[hidden email]> wrote:

> Hi Anandha,
>
> On Wed, Feb 27, 2013 at 01:01:24PM +0530, Anandha Kannan wrote:
>> Hi Ariel,
>>
>>   Thanks for the reply. I tried with modifying my code to wait till, OO
>> stats. But still, am ending with same exception.
>
> Did you wait until you checked that AOO was listening on the port?
> For now, just for testing purpose, you can put a cin.get(), and wait
> until you are sure that AOO is listening, then press ENTER to continue
> with your code.
>
>> To check whether the port has been opened in listening mode, I got the
>> following result for telnet and netstat (no listing of this port in netstat)
>>
>> admin$ telnet localhost 2081
>> Trying ::1...
>> telnet: connect to address ::1: Connection refused
>> Trying 127.0.0.1...
>> Connected to localhost.
>> Escape character is '^]'.
>> e??'com.sun.star.bridge.XProtocolPropertiesUrpProtocolProperties.UrpProtocolPropertiesTidݓ??
>
> This is ok, it's the expected result.
>
>> admin$ netstat -ntpl | grep soffice
>> netstat: l: unknown or uninstrumented protocol
>
> Seems MacOS uses the FreeBSD implementation, which does not support the
> same options as in Linux.
>
>> Also when i try to run your sample application, I get error,
>> "OpenOffice.org quit unexpectedly" and doesn't launch the process.
>
> Strange. I've just tested it, and works as expected:
> http://people.apache.org/~arielch/images/connaware1.png
> http://people.apache.org/~arielch/images/connaware2.png
>
> Please try putting a cin.get() in your code, and press Enter to continue
> only after you check that AOO is already listening. If after that you
> can connect, then it is a timing issue.
>
>
> Regards
> --
> Ariel Constenla-Haile
> La Plata, Argentina
Reply | Threaded
Open this post in threaded view
|

Re: Exception in connecting to socket

Ariel Constenla-Haile-2
Hi Anandha,

On Wed, Feb 27, 2013 at 07:31:18PM +0530, Anandha Kannan wrote:
> Hi Ariel,
>
>         Thanks for the input. But i tried my code with cin.get() and
>         ENTERED only after confirming that the port is listening
>         (using lsof -i :2081). Do u think there could be any other
>         possible reason for this issue?!

Hard to guess without seeing the code. Try the usual things:
- running the application as unprivileged user
- running the application inside a shell where the SDK environment was
  set
- strip the code: first try the code that connects with the
  UnoUrlResolver in a simple client application; if it works in this
  way, you have to investigate way it doesn't work when you insert the
  very same code in your application.

As a rule, always look at the way the SDK examples are launched
(-env:URE_MORE_TYPES=<...> and other switches are vital), this might be
the cause why the code works standalone but not when you copy it into
your application.


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment