Creating a Server PortAuthor: Paul Tretter Creating a server port is much different than a client port connection. The reason is because one server port must handle the data for many clients. The following shows how multiple clients can communicate with the REBOL server. First off you create a listen port (server port)- such as:
Now you have a listen port, but this port only listens for the connections so if you do a wait just on this port it will only respond to the connections and not the actual data sent from a remote connection. But we still have to wait on this port to monitor incoming connections:
Now we need to perform some check to identify incoming port connections. This is done by checking to see if there is an active port connection with:
This will return the active connection but not the data. This actually creates a new port object referencing this specific remote connection. We want to capture this remote connection for other communications so we would now have:
Active-port will contain a new remote connection's details into a new port object. So we add more code and logic and to this point would be:
We need to get the data that was sent but first we must wait on the new active-port so we append it to waitports.
To wait for port data on this port we again have to perform some logic and capture the incoming data and in this case print it. We modify our 'if statement to an 'either statement.
You can test this by running the above code from one console and the following from another:
Leave that console open and open yet another console and doing the same again but with "test2" as our string value.
Now you have successfully made a server that can handle multiple clients. Also notice that you can telnet to this port and send data also with:
|