help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cannot start listen command


From: charles reid
Subject: Re: cannot start listen command
Date: Fri, 5 Sep 2008 11:18:32 -0600

Well, I have two ideas, one is probably more likely to work (and more attractive) than the other.

PHP has a function to send data to a socket that's connected, called socket_send (http://nl3.php.net/manual/en/function.socket-send.php).  I think you would have to use socket_accept to connect with the open Octave socket (or you could use socket_sendto, which is a brute-force method that sends data to a socket whether it's connected or not), and then socket_send could be used to make PHP communicate with Octave.
There's also a socket_listen (http://nl3.php.net/manual/en/function.socket-listen.php), so first you create your socket, then you bind it to a name, then you start listening on it.  This would probably be the way to go with Octave returning results to PHP.
The PHP documentation has got some great examples and it's well-written, so that should definitely help you out a lot.

The second idea...

> Also I would like to
> have the Ocatve code running all the time, or at least have access
> to large amount of data in the internal memory without having to
> make a slow load from the harddrive between the calls. Also there
> may be several user access this information at the same time.

I'm not sure exactly what you mean by this, and this suggestion may not satisfy your needs, but you could try using files as an intermediary (i.e. PHP writes input to file, calls octave using a program execution function (more info here http://nl3.php.net/manual/en/ref.exec.php), octave writes the output to another file, and php reads & displays it to the user).  This would definitely be slower, but if you need to get something working quick, but you need more time to figure out the socket-to-socket stuff, this may be a good intermediate solution.

This has captured my interest, I will be playing around with this more to see if I can get it working.  Please let us know how this goes for you.


Charles

On Thu, Sep 4, 2008 at 10:00 PM, Sverker Sikström <address@hidden> wrote:
Hi Charles

Thanks a lot! The demo worked fine and it is easy to see how the calls must be made and what needs to be initalized. If you happen to know how to send thing from PhP then lets us know. Otherwise thanks a lot for the help!

Sverker


charles reid skrev:
The original author of the sockets package put together a test program, which can be found here (http://article.gmane.org/gmane.comp.gnu.octave.sources/60) and is included below.  Also, you might try 'man listen' from a Unix command line, since it's the Unix listen that the sockets package is calling.
## Tests for octave sockets
##

function test_octave_socket()
 page_screen_output = 0
       load_socket_constants

 fail = 0

 # Create the sockets
 ## Server socket
 server = socket(AF_INET, SOCK_STREAM, 0)

 if( server < 0 )
   ++fail
   return
 end

 rc = bind(server,9001)
 if( rc ~= 0 )
   ++fail
   return
 end

 rc = listen(server,1)
 if( rc ~= 0 )
   ++fail
   return

 end

 ## Client socket
 client = socket(AF_INET, SOCK_STREAM, 0)
 if( client < 0 )
   ++fail
   return
 end

 # Create the connection and accept the connection
 server_info = struct("addr","127.0.0.1 <http://127.0.0.1>", "port",9001)


 rc = connect(client, server_info)
 if( rc ~= 0 )
   ++fail
   return
 end

 server_data = accept(server)
 if( server_data < 0 )
   ++fail
   return
 end

 # Send and receive data

 ## Send as string from client
 msg = "Hello socket-land!"
 rc = send( client, msg )
 if( rc ~= length(msg) )
   ++fail
   return
 end

   ## Receive at server
 [msg_s, len_s] = recv( server_data, 100 )

 if( msg_s == -1 || len_s ~= length(msg) )
   ++fail
   return
 end

 ## Send back out from server
 rc = send( server_data, msg_s )
 if( rc ~= length(msg_s) )
   ++fail
   return
 end


 ## Receive at client
 [msg_c, len_c] = recv( client, 100 )
 if( msg_c == -1 || len_c ~= length(msg) )
   ++fail
   return
 end

 ## Compare original string with recv string
 msg_in = num2str( msg_c, '%c' )

 if( msg_in ~= msg )
   ++fail
   return
 end

       rc = disconnect( client )
       rc = disconnect( server_data )
       rc = disconnect( server )
       
 printf( 'Number of failures: %d\n', fail )


end
 
Hope this helps.


Charles

On Thu, Sep 4, 2008 at 10:56 AM, charles reid <address@hidden <mailto:address@hidden>> wrote:

   Hi Sverker -

   Don't you want listen('127.0.0.1 <http://127.0.0.1>','fork')?



   Charles


   On Thu, Sep 4, 2008 at 7:24 AM, Ben Abbott <address@hidden
   <mailto:address@hidden>> wrote:



       On Sep 4, 2008, at 8:29 AM, Sverker Sikström
       <address@hidden
       e> wrote:

       > Dear Ben
       >
       > Thanks a lot for you very helpfull instruction of how to get
       going
       > with the Listen command a few weeks back. I did get command
       > "started" using your help, however, I have not been able get it
       > going yet. I would very much appreciate a helping hand here.
       >
       > My goal is to have Php programm communciating with Octave,
       so that
       > one can that when a visotor click on a webpage than this
       webpage can
       > send string to Octave that makes a calcualtion and send its
       back to
       > the webpage (where we use Php) at the webpage. Also I would
       like to
       > have the Ocatve code running all the time, or at least have
       access
       > to large amount of data in the internal memory without having to
       > make a slow load from the harddrive between the calls. Also
       there
       > may be several user access this information at the same time.
       >
       > I am not sure how to do this. But I think the Listen command
       would
       > be the way to go. Is that correct?
       >
       > I try to run listen with:
       >
       > octave-3.0.1:1> pkg load sockets
       > listen('128.0.0.1 <http://128.0.0.1>','fork')

       > error: connect: expecting a octave_socket or integer
       > octave-3.0.1:2>
       >
       > But I get an error message (see above). I guess I have the wrong
       > call, or perhapse I need to initaitve something before.
       >
       > Once this code in the Octave is up and running. Then how do
       you call
       > this rotine from Php?
       >
       > I would appreciate help on this topic very much. If you do
       not know
       > how to set this up, please suggest someone that could help
       us out on
       > this.
       >
       > Sincerely, Sverker Sikström
       >
       > Ben Abbott skrev:
       >>
       >> On Aug 11, 2008, at 5:05 AM, Sverker Sikström wrote:
       >>
       >>> Hi
       >>>
       >>> This is probabaly a very simple questions, but I am stuck
       and new to
       >>> Octave. I am trying to run the command 'listen'
       >>> (http://octave.sourceforge.net/doc/f/listen.html) on
       Octave. But
       >>> it does
       >>> not seem to find the command:
       >>>
       >>> octave-3.0.1:46> listen
       >>> error: `listen' undefined near line 46 column 1
       >>> octave-3.0.1:46>
       >>>
       >>> Have I not installed Octave correctly? I am using mac 0s
       10.5. 4.
       >>> Any
       >>> help is appreciated!
       >>>
       >>> Sverker
       >>
       >> I haven't tried to do this under Mac OS X, but you'll need to
       >> install the sockets package from Octave-Forge. The "listen"
       command
       >> is part of that package (it is not part of Octave's core
       functions).
       >>
       >>    http://octave.sourceforge.net/sockets/index.html
       >>
       >> To install see "help pkg"
       >>
       >> Ben

       Unfortunately, I'm not knowledgeable in what you'd like to do
       ..., so
       I've cc'd Octave's help list. Hopefully someone will be able
       to answer
       your questions.

       Ben
       _______________________________________________
       Help-octave mailing list
       address@hidden <mailto:address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]