[Top][All Lists]

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

[gforth] socket.fs getting started problem

From: kibler
Subject: [gforth] socket.fs getting started problem
Date: Tue, 17 Apr 2012 10:25:13 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.3) Gecko/20120329 Icedove/10.0.3

Now that we have the serial interface working again in gforth 7.9+,
I am turning my attention to adding enhancements to our application.
We use serial interface to talk to our development boards and would
like to be able to talk using network to serial adapters. We have used
the wiznet adapters in other applications and for their $25 price they
work very well.

I have tried to find examples using sockets and can only find the
repost.fs that seems to be the recommended example to use. However that
example is for 6.2 gforth and after several attempts to use it with
7.9+, have gotten no where.

I tried using the program netcat or "nc" as a openpipe compromise
to just pipe the data between nc and gforth. I can read the data,
but was unable to open the pipe both r/w, only read or write, not
both. Not sure if that is correct or not, but felt I should be able
to open it r/w, so I think that might be broken as well. Our application
uses the key?-file to see if anything is pending and both the select
and poll return only "0" when key?-file is called. I did see a "-1"
once using poll, but mostly returns "0" when I know data is present.

So, I am asking for working examples of the use of sockets or help
in fixing the test code I provide below, for 7.9+, as we want to
move to the newest code and any enhancements to gforth they provide.
We know it is just time before our use of gforth 6.2 no longer works
on current versions of linux, so updating to the latest seems something
we need to get working.

The version of gforth I am using:
> gforth
Gforth 0.7.9-20120317, Copyright (C) 1995-2011 Free Software Foundation, Inc.

The test code based on repost.fs to just open a socket for reading:

\ test.fs - test to see if can open a socket...
require unix/socket.fs

2000 constant nntp

1024 constant status-buf-len
create status-buf status-buf-len 2 + chars allot

: read-status { sock -- ior }
    sock stdout = if \ for debugging
        0 exit endif
    status-buf status-buf-len sock read-line throw 0= -39 and throw { len }
    status-buf c@ [char] 1 [char] 3 1+ within if
        status-buf len type cr
        status-buf len type cr
        -21 \ unsupported operation
    endif ;

: repostx
    s" " 2000 open-socket sock !

: repost
    parse-name { d: server }
    server nntp open-socket { sock }
    sock read-status throw
\    s" AUTHINFO USER " sock write-file throw user sock write-line throw
    sock read-status throw
\    s" AUTHINFO PASS " sock write-file throw passwd sock write-line throw
    sock read-status throw
\    start-id articles start-articles sock process-articles
\    s" QUIT" sock write-line throw
    sock read-status throw
    sock close-file throw ;

A couple of tests and their results:

> gforth test.fs -e "repost localhost bye"

*OS command line*:-1: Invalid memory address
>>>repost<<< localhost bye
$7FD0ED587640 call-c
$7FD0ED587588 execute
$7FD0ED5A30D8 getaddrinfo
$7FD0ED5A34F0 get-info
$7FD0ED5A5710 open-socket

> gforth test.fs -e "repostx bye"

*OS command line*:-1: Invalid memory address
>>>repostx<<< bye
$7F30D73FB640 call-c
$7F30D73FB588 execute
$7F30D74170D8 getaddrinfo
$7F30D74174F0 get-info
$7F30D7419660 open-socket

looks like something to do with passing of pointers?
Haven't started debugging in detail yet - thought I would
give others a chance to see if they have solved this already,
or have working examples to show me.


P.S. - here is what nc returns when invoked:

> nc localhost 2000

Test120 Display

Temperature of CPU in hex is: bb50
Temperature of CPU in C   is: 35.59

Data buffer in xram

     00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
2e00 54 42 30 31 bb 30 0a 18 95 a5 00 00 00 00 00 00
     T  B  0  1  .  0  .  .  .  .  .  .  .  .  .  .
2e10 3c 68 74 6d 6c 3e 3c 62 6f 64 79 3e 3c 70 3e 74
     <  h  t  m  l  >  <  b  o  d  y  >  <  p  >  t
2e20 65 6d 70 65 72 61 74 75 72 65 20 69 73 20 3a 20

reply via email to

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