1. how to communicate with a server?
- Posted by Bayes63 Oct 15, 2010
- 1767 views
Hi Guys, I've written a program (using EuWinGui + 3.1.1) and need to add some code which sends a number to a server when a button is clicked, the server (a CGI program) then sends back some number(s) to my program, which are then processed, and the process repeats. Having never done any network programming before I'm not sure which of the libraries/functions should be used to accomplish this, so I'd be grateful for some advice. I think this might be easier using Eu 3.0, but I want to use the EuWinGui library - has anyone tested it on 3.0? Many thanks.
2. Re: how to communicate with a server?
- Posted by mattlewis (admin) Oct 15, 2010
- 1883 views
Hi Guys, I've written a program (using EuWinGui + 3.1.1) and need to add some code which sends a number to a server when a button is clicked, the server (a CGI program) then sends back some number(s) to my program, which are then processed, and the process repeats. Having never done any network programming before I'm not sure which of the libraries/functions should be used to accomplish this, so I'd be grateful for some advice. I think this might be easier using Eu 3.0, but I want to use the EuWinGui library - has anyone tested it on 3.0? Many thanks.
I would recommend sticking with 3.1.1 over 3.0.
As for networking, I would recommend eunet. I believe that this library was the basis for the networking in 4.0.
Matt
3. Re: how to communicate with a server?
- Posted by Bayes63 Oct 15, 2010
- 1754 views
Thanks Matt, actually, I meant to say version 4.0, not 3.0.
4. Re: how to communicate with a server?
- Posted by ChrisB (moderator) Oct 15, 2010
- 1752 views
Hi
EuWinGui won't work with 4. I have emailed Andrea Cini a awhile ago, and while he is interested in porting it, I don't think its a very high priority for him at the moment.
Chris
5. Re: how to communicate with a server?
- Posted by Bayes63 Oct 15, 2010
- 1715 views
Thanks for letting me know, Chris. I was just about to download 4.0, you've saved me the trouble. I'm not sure which function from Eunet I need;my understanding of http is close to zero, but I'll play around for a little while.
6. Re: how to communicate with a server?
- Posted by irv Oct 15, 2010
- 1727 views
http://rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=socket
Several examples & packages there. I need to update my programs there to use Eu4.0.
7. Re: how to communicate with a server?
- Posted by euphoric (admin) Oct 15, 2010
- 1704 views
...need to add some code which sends a number to a server when a button is clicked, the server (a CGI program) then sends back some number(s) to my program, which are then processed, and the process repeats.
I've been doing this since at least 2003 using mic's urlmon. Don't know if that's the easiest way today, though. I should look into that... :)
8. Re: how to communicate with a server?
- Posted by euphoric (admin) Oct 15, 2010
- 1694 views
EuWinGui won't work with 4.++ I have emailed Andrea Cini a awhile ago, and while he is interested in porting it, I don't think its a very high priority for him at the moment.
It can't be all that difficult to convert. Win32Lib was a breeze and probably has more lines of code. Come on!
9. Re: how to communicate with a server?
- Posted by mattlewis (admin) Oct 15, 2010
- 1708 views
EuWinGui won't work with 4.++ I have emailed Andrea Cini a awhile ago, and while he is interested in porting it, I don't think its a very high priority for him at the moment.
It can't be all that difficult to convert. Win32Lib was a breeze and probably has more lines of code. Come on!
I was just taking a look at it. It uses a dll, which appears to accept and return native euphoria objects. The formats for atoms and sequences have changed, which is what appear to be causing machine crashes. The only solution I could see would be to write a shim dll that would convert between the two. I suspect this is a dll built by translating euphoria code (though it could be something else that uses the old euphoria object ABI). Either way...Ugh.
Such is the peril of unsupported proprietary code.
Matt
10. Re: how to communicate with a server?
- Posted by Bayes63 Oct 15, 2010
- 1731 views
Thanks for the feedback guys. I've just been looking at the readme in Eunet.
quote:
"Socket programming can be either client/server or peer-to-peer. In client/server, one copy of the program listens for incoming connections, while all other copies create those connections. In peer-to-peer, all copies are both listening and connecting."
I'm totally clueless. What I want to do isn't as simple as remotely downloading a web page, is it? otherwise I could just use wget. Don't I need to use some of these functions?
HTTP routines are...
eunet_get_http_use_cookie
eunet_get_recvheader
eunet_get_sendheader
eunet_get_url
eunet_parse_recvheader
eunet_set_sendheader
eunet_set_sendheader_default
eunet_set_sendheader_useragent_msie
eunet_urlencode
DNS routines are...
eunet_dnsquery
eunet_getaddrinfo
eunet_getmxrr
eunet_getnsrr
Initialization routines are...
eunet_accept
eunet_bind
eunet_connect
eunet_get_socket_options
eunet_listen
eunet_new_socket
eunet_set_socket_options
Communication routines are...
eunet_poll
eunet_recv
eunet_recvfrom
eunet_send
eunet_sendto
Cleanup routines are...
eunet_close_socket
eunet_shutdown_socket
But I don't know which ones and in what order. The examples which come with the library aren't helping much.
11. Re: how to communicate with a server?
- Posted by euphoric (admin) Oct 15, 2010
- 1770 views
Oh. Well, there are other GUI libs available anyway. Even some cross-platform ones! :)
12. Re: how to communicate with a server?
- Posted by irv Oct 15, 2010
- 1718 views
Since you said a cgi program, I'm guessing you're going to be running a web server - such as apache.
If so, look at socks which is a very simple program with enough socket stuff to do the job. about 250 lines, so it's easy to follow.
OTOH, perhaps you want to use RPC (remote procedure calls). Dave Cuny has a package: RDC which USED to work fine, but for some reason, does not now work on my Linux computer - perhaps some addition security measures are preventing it from working. All calls to accept fail.
13. Re: how to communicate with a server?
- Posted by Bayes63 Oct 15, 2010
- 1705 views
Hi irv,
Thanks for the link. I'm not running a server, and I'm probably making this sound more complicated than it actually is. Basically, I want to capture the data in a euphoria program which would otherwise be shown in a browser. So imagine there is a web page with a text field and a button. I enter a number into the text field and then hit the button (a request). The request initiates a CGI program on the server which accepts the number and does some processing, then writes a new page with some new numbers (which I would see on the page if this were all done from a browser). So the code I need is all "client" code, I'm not concerned with what goes on in the server, I just need to be able to read the "response" directly into my program (instead of reading it on the page).
14. Re: how to communicate with a server?
- Posted by irv Oct 15, 2010
- 1716 views
include std/net/http.e -- Eu4.0 enum HEADER, BODY object data data = get_url("http://foo.com/cgi/somecgi","userid=joe&password=guessme") puts(1,data[HEADER]) -- do something with data[BODY], like parse out the info you need...
Now, if you're accessing a web page (yours or someone else's) with a browser to enter the numbers & press the button, you are going to get the results back as a web page in the browser - which Euphoria won't see.
So probably you'll want to determine from looking at the first web page source what the names of the fields are, and use those in your get_url() request instead of entering them on the original web page. Confused?
Here's a simple web form: http://isthe.com/cgi-bin/cgi-example.cgi Look at it first with a browser, then view the source. You'll see the names of the form fields, like <input type="text" name="yourname" value="Your name here" /> Use those field names to send data directly from your Euphoria program.
if you request that page using the above short program with the line:
data = get_url("http://isthe.com/cgi-bin/cgi-example.cgi","yourname=FooBaz&color=blue")
The returned web page will have html using those values:
Your name is: <b>FooBaz</b> <p /> The keywords are: <em></em> <p /> Your favorite color is: <tt>blue</tt>
Obviously, you'll have to parse out the parts you need to use.
If you're writing the cgi yourself, it's much easier - you don't need to return a web page full of html at all, just send plain text back.
15. Re: how to communicate with a server?
- Posted by Bayes63 Oct 15, 2010
- 1642 views
Irv, Now that's more like it! thanks very much - this is exactly what I need. There's a snag though, in that I'm using Eu 3.1.1 with the EuWinGui library, which apparently doesn't work with Eu 4.0. Would it be possible to use the relevant include file(s) from 4.0 in 3.1.1? or does the new "standard library" make use of new features in 4.0 which 3.1.1 doesn't have?
Otherwise, I can either use Win32lib (which I assume DOES work with 4.0) or else use EuWinGui and try to find a way to achieve what get_url() does using eunet in 3.1.1. Not sure which is the lesser evil.
16. Re: how to communicate with a server?
- Posted by irv Oct 15, 2010
- 1675 views
eui socks isthe.com /cgi-bin/cgi-example.cgi?yourname=Irv&color=red
If you get the sockets demo previously mentioned, it has the ability to do the same, and it runs in 3.11 Use a command line similar to the one shown above, or use the routines in it as you need. Just cut out the - - MAIN - - part and use the rest as an include, calling Get("hostname","filename")
However - you may have to change some code to make it work on Windows - I don't have access to a Windows machine, and you probably have to call a different dll to get the functions to work. Looks like the equivalent Windows calls can be found here: TCP Socket Library
17. Re: how to communicate with a server?
- Posted by useless Oct 15, 2010
- 1672 views
Regardless of the programming language you use, wget.exe is easy to use to do GET or POST. Someone else and i just ran a couple million web transfers by calling wget to POST data and GET results.
Else, use Eu4 and look at everything http related in Drive:\euphoria40b2\demo\.
Of course if it's your host, you could use any protocol besides http.
useless
18. Re: how to communicate with a server?
- Posted by Bayes63 Oct 16, 2010
- 1580 views
Thanks irv for the suggestions. As I've already written the gui (which is fairly complex) and most of the associated code, I'm a bit loathe to start over with win32lib and eu 4.0, so I might take a look at wget (thanks useless). I wasn't aware that you could use it for this kind of application. I assume I can't "capture" the data in the way I would be able to useing get_url(), but it's no big deal to save it to file and read from that.
19. Re: how to communicate with a server?
- Posted by Bayes63 Oct 16, 2010
- 1586 views
I don't use Windows, but as the program will be distributed to others (who mostly do use it), I'm just wondering whether I should include a copy of wget.exe or does it come "bundled" with Windows? I know it's included in most Linux distributions.
20. Re: how to communicate with a server?
- Posted by irv Oct 16, 2010
- 1516 views
I doubt it comes with Windows - hardly anything useful comes with Windows.
You'll need to include the complete wget installer, since there are some dll dependencies as well as wget itself. You really should just use the TCP library mentioned earlier, so you can read & use the data directly, and have only 1 program for your users to install.
21. Re: how to communicate with a server?
- Posted by useless Oct 16, 2010
- 1558 views
I doubt it comes with Windows - hardly anything useful comes with Windows.
You'll need to include the complete wget installer, since there are some dll dependencies as well as wget itself. You really should just use the TCP library mentioned earlier, so you can read & use the data directly, and have only 1 program for your users to install.
You can "install" wget.exe and all "dependancies" by simply dropping all the files that come with wget into the same folder. You can include those files in your program zip file (subject to whatever licensing legalese), unzip to any folder you want (i use a subdir of "wget" to each app), there's no environment vars to set up to use wget, altho you can, if you want, make and use the config file mentioned in wget's readme manual.
Save the recieved file to the same name always, which you delete, and allow the OS time to delete it, before calling wget, so if the file is there, and ends in </html>, it's valid for the call you just made. Specify the timeout of non-reciept of file to something reasonable, in your Eu app do a sleep(1) and poll for the recieved file being there using open("blah","rb") or something.
useless
22. Re: how to communicate with a server?
- Posted by jaygade Oct 16, 2010
- 1452 views
wget is free software. It is distributed under GPL v3, so if you distribute wget with your own software, make sure to distribute a copy of the license as well.
As Kat says, you should be able to just dump all of its files into its own directory and run it from there. There are 4 DLLs and two EXEs distributed, along with a sample rc (configuration) file and a root certificates file for SSL (which is one of the EXEs distributed).
23. Re: how to communicate with a server?
- Posted by Bayes63 Oct 17, 2010
- 1487 views
Thanks for the input guys. The version I downloaded was a single 400kb exe, from http://users.ugent.be/bpuype/wget/
Strange, there should be a tilde in front of "bpuype", it's not showing, which is why you get a "not found" error when clicking the link.