[Solved] Sending/Receiving info To/From TCP/IP Server

Creating a macro - Writing a Script - Using the API

[Solved] Sending/Receiving info To/From TCP/IP Server

Postby Satsuki » Thu Nov 05, 2009 4:29 pm

I would like to use OpenOffice to my application. I have a server. A server conect to google research and it retrieves a sequence. This sequence is send to openoffice. But I am unsure how to program the TCP socket client to send and recive sequences.

I use python to program my application. A server operate because I do a temporaly client for evaluate the server.
But I need to know if is possible create TCP client in openoffice for send and recieve sequences. In openoffice the user select a text with the cursor. I want send this selection to socket server, but I don't know how to program the TCP/IP socket connection.

¿Any example?

Thanks
Last edited by Satsuki on Wed Nov 11, 2009 7:58 pm, edited 2 times in total.
OpenOffice 3.1 on Ubuntu 8.04
Satsuki
 
Posts: 11
Joined: Tue Nov 03, 2009 7:59 pm

Re: Sending/Receiving info To/From TCP/IP Server

Postby Villeroy » Thu Nov 05, 2009 4:55 pm

I never tried but we can submit input forms through HTTP get or post without coding. See the "General" tab of a form's properties.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 29474
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Sending/Receiving info To/From TCP/IP Server

Postby hanya » Thu Nov 05, 2009 5:37 pm

There is socket library in the Python standard library.
Here is an example and it worked on my environment between locally installed python as server and python instance of OOo.
http://docs.python.org/library/socket.html#example
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Sending/Receiving info To/From TCP/IP Server

Postby Satsuki » Thu Nov 05, 2009 11:42 pm

Thanks for response.

I tester two codes and I have some problems:

Code: Select all   Expand viewCollapse view
import uno

import socket

def send():

   HOST = ''    # The remote host
   PORT = 4001              # The same port as used by the server
   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   s.connect((HOST, PORT))
   s.send('Hello, world')
   data = s.recv(1024)
   s.close()
   print 'Received', repr(data)


Code: Select all   Expand viewCollapse view
    import uno

    from socket import *

    server = ''

    port = 4001
   
    def(send):

        s = socket(AF_INET, SOCK_DGRAM)

        s.connect((server, port))

        s.send('Hello world')

        answer = s.recv(1024)

        s.close()



I select Tools --> Marcros --> Organise Macros --> Python. Select the script send. Click ejecute.
I get the next error UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 42: ordinal not in range(128).traceback follows /opt/openoffice.org/basis3.1/program/pythonscript.py: 792 in function invoke() [self.mode,__file__+"(" + text + ")"]

¿Where is the problem?
Thanks
Last edited by Satsuki on Sun Nov 08, 2009 3:23 pm, edited 1 time in total.
OpenOffice 3.1 on Ubuntu 8.04
Satsuki
 
Posts: 11
Joined: Tue Nov 03, 2009 7:59 pm

Re: Sending/Receiving info To/From TCP/IP Server

Postby hanya » Fri Nov 06, 2009 7:27 am

Modify your code to find real error like the following:
Code: Select all   Expand viewCollapse view
   try:
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   except Exception as e:
      print("error at creation: %s" % e)

If you get Errorno 10061, change the PORT that you use.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Sending/Receiving info To/From TCP/IP Server

Postby Satsuki » Sun Nov 08, 2009 3:29 am

The error is the same, The new code don't get any error.

¿Have you got any operate example?
OpenOffice 3.1 on Ubuntu 8.04
Satsuki
 
Posts: 11
Joined: Tue Nov 03, 2009 7:59 pm

Re: Sending/Receiving info To/From TCP/IP Server

Postby hanya » Sun Nov 08, 2009 6:08 pm

The example mentioned above works with HOST='' and PORT=50007 for the server and HOST='localhost' and PORT=50007 for the client on my environment.

Satsuki wrote:The error is the same, The new code don't get any error.
What did you get with the modification...
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
 
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan


Return to Macros and UNO API

Who is online

Users browsing this forum: eeigor and 8 guests