0

I asked this question a few weeks ago about port Rebol Smallest Http Server in the World: why first wait listen-port?

listen-port is an object

first listen-port is self so still don't understand why self doesn't equal listen-port that is why do we need

http-port: first wait listen-port

if wait returns listen-port and first listen port is the same as self or listen-port then the above code is not the same as

http-port: wait listen-port

?

Community
  • 1
  • 1
Rebol Tutorial
  • 2,738
  • 2
  • 25
  • 36

1 Answers1

1

listen-port is a port! value, not an object! value. A port! can be seen as a derivation from object! datatype and having a specialized purpose. FIRST behaviour (as all other action! values) is polymorphic.

For object! values, it returns the list of words defined in that object context (plus the special self-referencing word 'self) :

foo: make object! [bar: 3]
first foo
== [self bar]

For port! values, FIRST will have two different behaviours depending on the port! type :

  • client port : it sends the PICK action to the port internal handler (first port == pick port 1).

  • server port : it will call the ACCEPT action to the underlying C socket to retrieve a new connection port! value, allowing communication with the client.

So :

wait listen-port

returns the listen-port value when an event happens.

http-port: first wait listen-port

returns a new port! value connected to the client referenced by 'http-port.

  • It does not assign a new port. The accepted socket uses the same port as the listening socket. – user207421 Jan 19 '16 at 01:26
  • @EJP You are misunderstanding what `port! value` mean in Rebol, it's a high-level abstraction, not a C-level socket nor a port number. In the above code, `http-port` and `listen-port` are effectively two different port! values. – DocKimbel May 25 '16 at 09:30