Arc Forumnew | comments | leaders | submitlogin
Ask Arc: Compatibility with IOLib or Similar?
3 points by christianbryant 2102 days ago | 12 comments
Some time ago I started to work with IOLib [1] in with the aim to start a Lisp project for some network testing in CL (in lieu of Guile for better portability).

I find myself with that need again and now in lieu of CL would like to try it in Arc. I need to write some basic test automation similar to the below (from the IOLib tutorial [2]).

Test Example: Daytime Client IVP4/TCP: ex1-client.lisp - This example is a very simple daytime client program which contacts a server, by default at 'host' and 'port', returns a single line of text that is the current date and time, and then exits.

New to Arc, I'm wondering how compatible would an Arc program be with IOLib? All the code I worked with previously were run with SBCL. If not IOLib, are there recommendations?

[1] https://common-lisp.net/project/iolib/ [2] http://pages.cs.wisc.edu/~psilord/blog/data/iolib-tutorial/tutorial.html



3 points by zck 2102 days ago | link

Arc is definitely not going to be able to use IOLib. If you want to find some libraries, you might be able to use some Racket libraries.

I'm not sure if you're looking to write the server component, or the code that contacts the server.

If you want to make a webpage that returns the current date and time, it's either straightforward or complicated, depending what exactly you want.

If you want a webpage that returns the current date and time _in UTC_, it's straightforward:

    arc> (thread (serve 8080))
    #<thread>
    arc> ready to serve port 8080
    arc> (defop hello req (let (sec min hour day month year) (timedate) (prn year "-" month "-" day " " hour ":" min ":" sec)))
    #<procedure: g20474>
If you want it in your local timezone, that's more complicated. You might have to pull in Racket libraries.

-----

3 points by akkartik 2102 days ago | link

I just went through this exercise as well. Once you define the server, you can then query it with this code:

    arc> (load "lib/client.arc")
    arc> (cdr (mkreq "http://localhost:8080/"))

-----

3 points by zck 2102 days ago | link

Ooh, interesting! We might want to figure out a long-term documentation system for Anarki; the existing arclanguage.github.io documentation is for Arc 3.1. And while that's great, it's suboptimal for cases like this, because it says "...there is no support for outgoing network connections." (https://arclanguage.github.io/ref/networking.html).

-----

2 points by akkartik 2102 days ago | link

Yeah, there's a reason why the documentation isn't linked on the right side at http://arclanguage.github.io :/

-----

3 points by christianbryant 2101 days ago | link

How about UDP calls? I sucked this CL snippet a while back (sorry I don't have the author info at hand). Creates a socket, sends data and receives data:

  (defun create-client (port buffer)
     (let ((socket (usocket:socket-connect "127.0.0.1" port
					 :protocol 
                                         :datagram
					 :element-type 
  '(unsigned-byte 8))))
    (unwind-protect
	 (progn
	   (format t "Sending data~%")
	   (replace buffer #(1 2 3 4 5 6 7 8))
	   (format t "Receiving data~%")
	   (usocket:socket-send socket buffer 8)
	   (usocket:socket-receive socket buffer 8)
	   (format t "~A~%" buffer))
      (usocket:socket-close socket))))

-----

2 points by hjek 2075 days ago | link

Check the Racket docs on UDP[0]. Arc itself is very high-level, but you can do more low-level stuff via Racket interop.

[0]: https://docs.racket-lang.org/reference/udp.html

-----

2 points by christianbryant 2101 days ago | link

Appreciate it. I want to just write the code that contacts the server. Some Python pseudocode to represent the basics is below, but that just represents basic socket foo, minus the code for authentication, etc. The code would run through a list of 20+ systems and just connect one by one and log that system's local datetime. The assumption is we're doing UDP communication.

  client = socket
  host = local_system
  data = datetime_query
  remotedata = datetime_response
  target = remote_system

  client.connect (remotehost, port)
  client.send (data, target)
  remotedata.receive (remotedata, host)

  if remotedata:
	print 'Remote system date and time is:', remotedata
	else print 'No data received.'

-----

3 points by akkartik 2102 days ago | link

Thanks for the pointer to IOLib! We don't have anything like it, but there is an http client: https://github.com/arclanguage/anarki/blob/master/lib/client.... It also has unit tests, so is unlikely to have suffered bitrot.

I've built an http client several times in my life, particularly in Wart (https://github.com/akkartik/wart/blob/master/073http_get.war...) and in Mu (http://akkartik.github.io/mu/html/092socket.mu.html#L35). So I'd be happy to help if you want to try to put something together yourself.

-----

3 points by christianbryant 2101 days ago | link

Thanks, Kartik!

I appreciate the info. I was actually just looking at Mu since I cloned that code for review recently. Since the framework I'll be doing this in is a testing suite, Mu may be the best model for me to follow.

Since I'm focused on UDP, Looking at comments in ac.scm in Arc, I realized MzScheme might hold the answer - there are plenty of UDP functions in those libraries.

Let me poke around a but and I'll shoot you an email if I have something to pass by you for opinion.

-----

3 points by christianbryant 2101 days ago | link

It's about now I realize I'm using an old Arc (hence the MzScheme reference). Moving to arc-nu and Racket (as noted by Zachary) which provides all the UDP I need ;-)

I'll spend some time on this - appreciate the responses.

-----

4 points by akkartik 2101 days ago | link

Great. Just one caveat: we tend to have more experience with just Anarki (https://github.com/arclanguage/anarki) which is also using the latest Racket.

If you're thinking of https://github.com/arclanguage/arc-nu, the author hasn't been active here in a while, so you may need to ping Pauan separately.

-----

3 points by christianbryant 2101 days ago | link

Ah... thanks for that note. I am working with Anarki primarily now as noted earlier for News and similar, but also didn't catch on that it was the main working model here.

-----