Chat server: Difference between revisions

m
(Dialects of BASIC moved to the BASIC section.)
m (→‎{{header|Wren}}: Minor tidy)
 
Line 3,806:
 
As Wren's VM is single threaded we create separate VMs to service each potential client connection (limited to 10) which run in their own thread. As the only way for the VMs to share mutable state is to use global variables within the host, synchronization is needed when accessing such variables.
<syntaxhighlight lang="ecmascriptwren">/* chat_serverChat_server.wren */
 
class Clients {
Line 4,007:
<br>
We now embed this in the following C program, build and run it to start the server. To end the server, just press control-C. For testing purposes, clients can use telnet from separate terminals to connect to the server on port 5000.
<syntaxhighlight lang="c">/* gcc chat_serverChat_server.c -o chat_serverChat_server -lpthread -lwren -lm */
 
#include <sys/socket.h>
Line 4,287:
config.bindForeignMethodFn = &bindForeignMethod;
const char* module = "main";
const char* fileName = "chat_serverChat_server.wren";
script = readFile(fileName);
 
Line 4,360:
return 0;
}</syntaxhighlight>
 
=={{header|zkl}}==
{{trans|Python}}
9,476

edits