Arc Forumnew | comments | leaders | submitlogin
3 points by zck 336 days ago | link | parent

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 336 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 336 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 336 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 336 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 310 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 336 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.'

-----