1. Linux sockets
Hello everyone,
Does anyone know how to send text/data through Linux sockets using
Euphoria ?
Regards
--
Peter Blue
IT Director - Legend Interactive Ltd
Technical Director - Platinum Communications Ltd
Please visit our web sites
http://www.yes-property.co.uk - International Estate Agents
http://www.legend-i.demon.co.uk - Legend Interactive Ltd
2. Re: Linux sockets
On 0, Kat <kat at kogeijin.com> wrote:
>
> Can i beg/pay anyone using nix to make it run as a remote http relay with a
> spot for me to plug in other functions between the relay in/out parts? Even if
> i
> recode it, i cannot justify testing code on a box i don't own, possibly
> crashing it when others are using the box. This code doesn't look async, is
> it? If not, can it be made async? i cannot allow it to use 100% of cpu on a
> remote shell.
>
> Kat
>
I don't have my Linux EU proxy server code anymore (that never really
worked
anyways) but I'll go over the libs I have and see what I can whip up for
you
I guess.
Be warned: I can TRY to get you something, but I an not guarrentte it
will
work. (Note that I use Linux, not FreeBSD. Shouldnt make that big a
difference,
though.)
jbrown
Linux User:190064
Linux Machine:84163
--
3. Re: Linux sockets
On 0, Peter.Blue at legend-i.demon.co.uk wrote:
> Hello everyone,
>
> Does anyone know how to send text/data through Linux sockets using
> Euphoria ?
>
> Regards
Yes, but I wouldnt recommend doing it directly if you are new to it.
RDC.e is a good lib to look at, also, take a look at this simple
socket lib by Irv Mullins: (personally, I'd like NONBLOCKING
gethostbyname though - probably have to use emulated threads for that
tho)
---Cut Here---
-- Simple Sockets Lib by jbrown
-- Access to unix sockets and internet protocols
-- based on Simple Sockets Demo by Irv Mullins
include get.e
include dll.e
include misc.e
include machine.e
without warning
constant DEBUG = 0 -- 0 = off, 1 = on
constant
AF_UNIX = 1, AF_INET = 2, -- DOMAINS;
SOCK_STREAM = 1, SOCK_DGRAM =2, -- SOCKET TYPES;
F_SETFL = 4, O_NONBLOCK = 04000 -- PORT MODE PARAMS;
-- Links to routines in the socks library
constant
lib = open_dll(""),
fcntl = define_c_func(lib,"fcntl",{C_POINTER,C_INT,C_INT},C_POINTER),
sock = define_c_func(lib,"socket",{C_INT,C_INT,C_INT},C_POINTER),
htons = define_c_func(lib,"htons",{C_USHORT},C_USHORT),
connect = define_c_func(lib,"connect",{C_INT,C_POINTER,C_INT},C_INT),
read_ = define_c_func(lib,"read",{C_INT,C_POINTER,C_INT},C_INT),
write_ = define_c_func(lib,"write",{C_INT,C_POINTER,C_INT},C_INT),
close_ = define_c_proc(lib,"close",{C_INT}),
gethostbyname = define_c_func(lib,"gethostbyname",{C_POINTER},C_POINTER),
getservbyname =
define_c_func(lib,"getservbyname",{C_POINTER,C_POINTER},C_POINTER)
function deallocate_string(atom str)
object result
integer i
i = 0
result = ""
while peek(str+i) != 0 do
result &= peek(str+i)
i += 1
end while
return result
end function
global function SockRead(atom sockfd)
atom buffer, char, bytes_read
object line
buffer = allocate(1)
line = ""
while 1 do
bytes_read = c_func(read_,{sockfd,buffer,1})
if bytes_read < 1 then
exit
else
char = peek(buffer)
if char = 10 then
char = '\n'
elsif char = 13 then
char = ' '
end if
line &= char
end if
end while
if DEBUG then
puts(DEBUG,"READ: "&line&'\n')
end if
return line
end function
global procedure SockWrite(atom sockfd, sequence string)
atom str, fn
string &= 13&10
str = allocate_string(string)
fn = c_func(write_,{sockfd,str,length(string)})
if DEBUG then
puts(DEBUG,"WRITE: "&string&'\n')
end if
free(str)
end procedure
global procedure SockClose(atom sockfd)
c_proc(close_,{sockfd})
end procedure
global function GetHostbyName(sequence hostname)
-- Returns {name, #addr, node}
object host
atom str, fn
object addr
-- host info structure is;
object name,
aliases,
addrtype,
length,
node
str = allocate_string(hostname)
host = c_func(gethostbyname,{str})
free(str)
if host > 0 then
name = deallocate_string(peek4u(host))
length = peek4u(host+12)
addr = peek4u(peek4u(host+16))
node = peek4u(addr)
addr = sprintf("%d.%d.%d.%d",peek({addr,length}))
return {name,addr,node}
else
return -1
end if
end function
global function GetServbyName(sequence service, sequence proto)
-- Returns {name, #port, protocol}
atom str1, str2, fn
-- server info structure;
object name,
port,
protocol
str1 = allocate_string(service)
str2 = allocate_string(proto)
fn = c_func(getservbyname,{str1,str2})
free(str2)
free(str1)
if fn > 0 then
name = deallocate_string(peek4u(fn))
port = peek({fn+8,4})
port = port[1]*256+port[2]
protocol = deallocate_string(peek4u(fn+12))
return {name,port,protocol}
else
return -1
end if
end function
global function SockConnect(atom hostnode, atom port)
atom sockaddr, SOCKET
SOCKET = c_func(sock,{AF_INET, SOCK_STREAM,0})
if SOCKET < 0 then
return -1
else
sockaddr = allocate(16) -- thanks Pete Eberlein!
poke4(sockaddr, {
AF_INET +
c_func(htons,{port}) * #10000,
hostnode,0,0})
end if
if c_func(connect,{SOCKET, sockaddr,16}) = 0 then
return SOCKET
else
c_proc(close_,{SOCKET})
return -1
end if
end function
constant URL = 1, URI = 2, NODE = 3, -- host info
SERVICE = 1, PORT = 2, PROTOCOL = 3 -- service info
global function Get(sequence hostname, sequence filename)
object host, service, file, SOCKET
host = GetHostbyName(hostname)
if atom(host) then
return -1
elsif DEBUG then
printf(DEBUG,"Host: %s Addr: %s Node: %d\n",host)
end if
service = GetServbyName("http","tcp")
if atom(service) then
return -2
else
SOCKET = SockConnect(host[NODE],service[PORT])
if SOCKET < 0 then
return -3
end if
if DEBUG then
printf(DEBUG,"Service: %s Port: %d Protocol: %s\n",service)
end if
end if
--write(SOCKET, sprintf("GET /%s HTTP/1.0\n\n",{filename}))
SockWrite(SOCKET, sprintf("GET /%s HTTP/1.1\nHost: %s\n\n",
{filename,hostname}))
file = SockRead(SOCKET)
c_proc(close_,{SOCKET})
return file
end function
---Cut Here---
--
4. Re: Linux sockets
On 8 Nov 2002, at 8:57, jbrown105 at speedymail.org wrote:
<snip>
> I don't have my Linux EU proxy server code anymore (that never really
> worked
> anyways) but I'll go over the libs I have and see what I can whip up for
> you
> I guess.
>
> Be warned: I can TRY to get you something, but I an not guarrentte it
> will
> work. (Note that I use Linux, not FreeBSD. Shouldnt make that big a
> difference,
> though.)
I think there is a use for this on *nix, as i asked for it, and someone else did
also, and Robert hasto be using it in the email filter service he runs, and
anything one does on a reliable shell hosting company will be on some form
of *nix. I know i have seen httpd written for tcl, but darned if i can find them
now. I have used perl to do irc mirroring, but i don't want to nuke the shell or
host by using trial and error to get a http proxy on a *nix shell on the other
side of the Atlantic Ocean. I simply won't be responcible for other's losing the
use of the box because i want to experiment, and i can't have someone
standing by to restart it. The problem for those of us on windoze isn't the
generic code, it's the OS-specific interface: how to bind to sockets, release
them, send to and recieve from them. And remote admin'ing them, how to
start them, verify we have permissions to use the port, and anything else
different on *nix.
I did try to run a box on RedHat for about 6 months. Rebooting *nix every few
minutes, when the win95 box kept on chugging for weeks, wasn't my vision
of nirvana. I finally pulled the harddrive and set it on the shelf, where it is
currently doing a much better job collecting dust than it ever did as a puter
OS.
Kat
5. Re: Linux sockets
> I think there is a use for this on *nix, as i asked for it, and someone
else did
> also, and Robert has to be using it in the email filter service he runs,
and
> anything one does on a reliable shell hosting company will be on some form
> of *nix.
Hey, Kat, RDS offers a programming service... why don't you get them to do
it? Myself and, I'm sure, others on this list would be willing to contribute
financially to get the project done. What do you say, Robert?!
6. Re: Linux sockets
On 8 Nov 2002, at 14:33, C. K. Lester wrote:
>
> > I think there is a use for this on *nix, as i asked for it, and someone
> else did
> > also, and Robert has to be using it in the email filter service he runs,
> and
> > anything one does on a reliable shell hosting company will be on some form
> > of
> > *nix.
>
> Hey, Kat, RDS offers a programming service... why don't you get them to do
> it? Myself and, I'm sure, others on this list would be willing to contribute
> financially to get the project done. What do you say, Robert?!
Already asked, waiting on reply. It seems to be a generic enough request,
not infringing on the material parts of the listfilter. Using it would put Eu on
the map corner for internet conections on hosting companies, whether for
http, email, irc, mu*, etc.. like tcp.e and tcp4u does for windoze. Surely
someone besides RDS has done this at home, but i have no clue how the
code would be set up differently for remote admin across the internet.
Kat
7. Re: Linux sockets
> > Hey, Kat, RDS offers a programming service... why don't you get them to
do
> > it? Myself and, I'm sure, others on this list would be willing to
contribute
> > financially to get the project done. What do you say, Robert?!
>
> Already asked, waiting on reply.
Let us know what happens... :)
8. Re: Linux sockets
Since Kat and a few others are interested,
I'll provide some technical details about how
the mailing list filter (http://www.ListFilter.com) works.
ListFilter is not rocket science, although I've now added so many
subtleties to it that it's approaching true AI
It consists of two Euphoria programs
that can run on Linux or FreeBSD without any change.
The two programs share an EDS database (per mailing list)
containing all the configuration data, "good" and "bad" words etc.
for that list. One program runs 24/7 in the background as a "cron" job.
It uses Euphoria system commands like:
system("mail < mail-commands ...", 2)
to retrieve the incoming mail from Topica (or other system)
into a file, and:
system("sendmail Eu-forum-approve file-name ... ", 2)
to send approved messages back to Topica.
I don't use any fancy protocols, sockets or anything like that.
The program scans incoming messages for certain "bad" and
"good" words, etc. and makes a decision about whether to
immediately approve the message, or send it to the
administrator's (my) inbox for manual approval/rejection.
The ListFilter user manual is on listfilter.com
The commands I use are standard UNIX ones. You can get the
documentation with (for example): man sendmail
The second program is an admin program that
interacts with the user (me) over the Web.
It manipulates an EDS database (for each separate mailing list)
containing all info for that list.
It presents a GUI interface to the administrator using CGI,
letting him add or delete words, etc. There are a lot of other
parameters you can play with, but they aren't important
if you only care about the "technology" used.
I'm not prepared to release the source, but I have
already released the source for the 1000-file archive search,
and the 44000-message mailing list search.
Those are both CGI-based Euphoria programs.
After running them, click on "Powered by Euphoria"
to get the source.
CGI is a simple protocol. Inputs from the Web browser arrive
via standard input, or an environment variable, and
the CGI program running on the server generates an
HTML file as output through standard output (file handle 1 in Euphoria).
We have examples and tutorials for CGI on the RDS site.
If you want to pay me big bucks to set up a CGI Euphoria
program on your site, let me know.
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com
9. Re: Linux sockets
On 8 Nov 2002, at 18:43, Robert Craig wrote:
>
> Since Kat and a few others are interested,
> I'll provide some technical details about how
> the mailing list filter (http://www.ListFilter.com) works.
<snip>
I didn't care how the *filter* works, i don't know the first part of
setting up Eu
on the remote box and getting anything to run. I wanted the example of
what
happens and what Eu code to use to get an http request and send the
headers out the "back door" to me.
> If you want to pay me big bucks to set up a CGI Euphoria
> program on your site, let me know.
Well, i spose it's true, those who have money will make all the money.
People tell me "use Apache or Squid", which tell me nothing about how to
set them up or get input from them, or send the headers off to me at a
different ip# and port#, or if there is threading going on, or when to
read the
vars, or even if *nix programs are event driven. I wasn't thinking of "big
bucks", especially since i wouldn't be making any money off this project
anyhow. I was looking to show i could to the backend work, not learn to be
a
*nix guru and do the server setup on *nix in 2 or 3 years. Oh well, i'll
link off
this dialup, on windoze, and show all the wrong ways to get it done.
Kat
10. Re: Linux sockets
Kat writes:
> I didn't care how the *filter* works, i don't know the first part of
> setting up Eu on the remote box and getting anything to run.
> I wanted the example of what happens and what Eu code to use
> to get an http request and send the headers out the "back door" to me.
OK, sorry, let me quickly explain the very first steps.
If you are completely unfamiliar with Linux/Unix commands
or CGI you might need to buy a book or search the Web.
Any information about CGI can be applied to Euphoria
quite easily. CGI can be used with almost any language.
Also, each CGI program will probably need an HTML form
that lets the user specify inputs. You can view the source of
the HTML on our site for that.
I assume that you have an account on a Web host provider.
You have a certain allotment of disk space and monthly bandwidth.
I assume that you can log in via telnet, and use FTP to upload your files.
On either a Linux or FreeBSD system you should
install Euphoria for Linux. That means typing:
tar -xvz -f euphor23.tar
at the top level directory of your account.
That will give you the familiar Euphoria directory.
You should also set your EUDIR and PATH variables
in a file like .login or .profile or .cshrc in your top level directory.
Use:
ls -a
to see these hidden files.
On FreeBSD, you will have to replace euphoria/bin/exu
with the exu for FreeBSD on our download page.
Your Euphoria CGI programs go into a directory called cgi-bin,
which is probably under a directory called public_html.
For various reasons, it may also be necessary to
copy exu and any include files you need directly into cgi-bin.
The file permissions must be set to allow "execute" permission
on the main Euphoria file, and read access to all other Euphoria files.
e.g.
chmod 775 myprog.exu
should do the trick.
Unless you bind, or translate to C, you should
have a line at the top of your main Euphoria file,
that says:
#!./exu
That tells Linux (or FreeBSD) to run the exu interpreter on your file.
You should also make sure that your main Euphoria file
uses \n line terminators, not \r\n like on DOS/Windows
or you'll have a problem with #!./exu
ed can fix this for you, or you can FTP in text mode.
There's no need to get the service provider to install anything.
exu is a C program residing in your directory.
You should be able to use it.
Also, be careful that ex.err, ex.pro etc. have write permission
or are deleted before you start debugging your CGI program.
"with profile" can often be helpful in debugging when the program
runs without producing an ex.err, but fails to produce
acceptable output HTML.
The process that runs the CGI program is not owned by you,
but is probably in your "group", that's why you have to be careful about
file permissions.
If you have more questions, fire away.
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com
11. Re: Linux sockets
On 0, Ray Smith <smithr at ix.net.au> wrote:
> as a side note euTcp4u uses the C library Tcp4u ... which is a cross
> platform library. As far as I can tell it is mainly used under Linux.
> Libnet is also cross platform. I had always intended to port the
> Euphoria
> versions to Linux ... even "tried" a few times but failed due to my
> lack of knowledge :( .
>
> I know Tcp4u and Libnet both have missing features for "server based"
> work ... but there are other TCP libs out there that might have the
> features your after. It would be a "simple" :) matter of wrapping
> an already existing Tcp library.
>
I can confirm this. I found a port of euTCP4u to linux rather simple.
I did it in 20-30 minutes, but was discouraged from using it due to its
lack of features, and am now writing such a library for *nix in pure
Eu.
jbrown
--
are
12. Re: Linux sockets
On 0, Kat <kat at kogeijin.com> wrote:
> On 8 Nov 2002, at 8:57, jbrown105 at speedymail.org wrote:
>
> <snip>
>
> > I don't have my Linux EU proxy server code anymore (that never really
> > worked
> > anyways) but I'll go over the libs I have and see what I can whip up for
> > you
> > I guess.
> >
> > Be warned: I can TRY to get you something, but I an not guarrentte it
> > will
> > work. (Note that I use Linux, not FreeBSD. Shouldnt make that big a
> > difference,
> > though.)
>
> I think there is a use for this on *nix, as i asked for it, and someone else
> did
> also, and Robert hasto be using it in the email filter service he runs, and
> anything one does on a reliable shell hosting company will be on some form
> of *nix. I know i have seen httpd written for tcl, but darned if i can find
> them
> now. I have used perl to do irc mirroring, but i don't want to nuke the shell
> or
> host by using trial and error to get a http proxy on a *nix shell on the other
>
> side of the Atlantic Ocean. I simply won't be responcible for other's losing
> the
> use of the box because i want to experiment, and i can't have someone
> standing by to restart it. The problem for those of us on windoze isn't the
> generic code, it's the OS-specific interface: how to bind to sockets, release
> them, send to and recieve from them. And remote admin'ing them, how to
> start them, verify we have permissions to use the port, and anything else
> different on *nix.
>
Not much I can say here. If you wanted to do something like this, you
should
learn the *nix protocols, obviously. I was working on a simple sockets
lib,
with code from Irv Mullins and Pete Eberlein. I'll speed it up so I can
finish implementing the server code, then I'll release it to the list
(and the archives), perhaps that may help you out??
> I did try to run a box on RedHat for about 6 months. Rebooting *nix every few
> minutes, when the win95 box kept on chugging for weeks, wasn't my vision
> of nirvana. I finally pulled the harddrive and set it on the shelf, where it
> is
> currently doing a much better job collecting dust than it ever did as a puter
> OS.
>
Every few minutes? I run RedHat Linux, and have an uptime of 27 days
right now,
and server Linuxes tend to go on for years at a time. Hmm ... very
strange ...
> Kat
>
jbrown
--
13. Re: Linux sockets
On 9 Nov 2002, at 7:03, jbrown105 at speedymail.org wrote:
>
> On 0, Ray Smith <smithr at ix.net.au> wrote:
> > as a side note euTcp4u uses the C library Tcp4u ... which is a cross
> > platform library. As far as I can tell it is mainly used under Linux.
> > Libnet is also cross platform. I had always intended to port the
> > Euphoria
> > versions to Linux ... even "tried" a few times but failed due to my
> > lack of knowledge :( .
> >
> > I know Tcp4u and Libnet both have missing features for "server based"
> > work ... but there are other TCP libs out there that might have the
> > features your after. It would be a "simple" :) matter of wrapping
> > an already existing Tcp library.
> >
>
> I can confirm this. I found a port of euTCP4u to linux rather simple.
> I did it in 20-30 minutes, but was discouraged from using it due to its
> lack of features, and am now writing such a library for *nix in pure
> Eu.
Ok, i got a page up on a nix box that is written as needed in Eu. Still needs
the backside connection, which i hope to do with a ftp or telnet-like
connection.
Luc is still working on a Eu-Perl hybrid.
Kat
14. Re: Linux sockets
Kat wrote:
> I think there is a use for this on *nix, as i asked for it, and someone else
> did
> also, and Robert hasto be using it in the email filter service he runs, and
> anything one does on a reliable shell hosting company will be on some form
> of *nix. I know i have seen httpd written for tcl, but darned if i can find
> them
> now. I have used perl to do irc mirroring, but i don't want to nuke the shell
> or
> host by using trial and error to get a http proxy on a *nix shell on the other
>
> side of the Atlantic Ocean.
> I simply won't be responcible for other's losing the
> use of the box because i want to experiment, and i can't have someone
> standing by to restart it.
You shouldn't be able to nuke a Linux box unless you are root or a hacker
> The problem for those of us on windoze isn't the
> generic code, it's the OS-specific interface: how to bind to sockets, release
> them, send to and recieve from them. And remote admin'ing them, how to
> start them, verify we have permissions to use the port, and anything else
> different on *nix.
I don't think Unix sockets are that much different from Winsock 1.0.
Winsock 1.0 was designed to be compatabile with BSD sockets. I am comparing
some Unix code vs winsock.h now and at least the basic functions like connect()
are same.
> I did try to run a box on RedHat for about 6 months. Rebooting *nix every few
> minutes, when the win95 box kept on chugging for weeks, wasn't my vision
> of nirvana. I finally pulled the harddrive and set it on the shelf, where it
> is
> currently doing a much better job collecting dust than it ever did as a puter
> OS.
If you want to test your Linux code, you could try some smaller simple distro,
(I like Basic linux, it boots from 2 floppies)
or the Cygwin enviroment.
I don't use Linux as that much, but I never managed to lock it. Perhaps it is an
hardware incompality you may report?
Martin
15. Re: Linux sockets
But,
If you are doing cgi, the server has limits set and will kill the script
after a period of time(usually anywhere from 30 - 300 seconds) to help keep
this from happening.
Regards,
Robert Szalay
----- Original Message -----
From: <irv at take.maxleft.com>
Subject: RE: Linux sockets
>
>
> Martin Stachon wrote:
> >
> > You shouldn't be able to nuke a Linux box unless you are root or a
> > hacker
> >
>
> Depends on your definition of 'nuke'.
>
> It's possible to write a loop that will use 99.99% of the CPU cycles,
> and almost as easy to write a loop that will eat up all memory,
> plus all virtual memory. Either way, that effectively stops all other
> processes, including any chance to kill your runaway Euphoria program.
> Any user can do this, root permission is not required.
>
> I have had Linux run for 30+ days, until a programming error caused
> one of the above problems. Only way out is to reboot, which may
> create disk errors. So be careful.
>
> Irv
>
>
>
>
16. Re: Linux sockets
On 0, irv at take.maxleft.com wrote:
> Martin Stachon wrote:
> >
> > You shouldn't be able to nuke a Linux box unless you are root or a
> > hacker
> >
>
> Depends on your definition of 'nuke'.
>
> It's possible to write a loop that will use 99.99% of the CPU cycles,
> and almost as easy to write a loop that will eat up all memory,
> plus all virtual memory. Either way, that effectively stops all other
> processes, including any chance to kill your runaway Euphoria program.
> Any user can do this, root permission is not required.
>
> I have had Linux run for 30+ days, until a programming error caused
> one of the above problems. Only way out is to reboot, which may
> create disk errors. So be careful.
>
> Irv
>
Correct. This happened to me once, when I was expermienting with
simulating
threads. (It has also happened when the X Server was overloaded and
started
to slow, but I could always telnet and kill it that way.)
jbrown
--
17. Re: Linux sockets
Irv wrote:
> Martin Stachon wrote:
> >
> > You shouldn't be able to nuke a Linux box unless you are root or a
> > hacker
> >
>
> Depends on your definition of 'nuke'.
>
> It's possible to write a loop that will use 99.99% of the CPU cycles,
> and almost as easy to write a loop that will eat up all memory,
> plus all virtual memory. Either way, that effectively stops all other
> processes, including any chance to kill your runaway Euphoria program.
> Any user can do this, root permission is not required.
>
> I have had Linux run for 30+ days, until a programming error caused
> one of the above problems. Only way out is to reboot, which may
> create disk errors. So be careful.
I should have better said "Unix box". The BSD systems have better restrictions
on memory and CPU usage. I think the next version of Linux kernel (2.6 or 3.0)
is going to have such features too.
Martin