Simple webserver

Janis Papanagnou janis_papanagnou+ng at hotmail.com
Fri Oct 20 22:03:32 EDT 2023


On 20.10.2023 23:05, Paul Rubin wrote:
> Janis Papanagnou <janis_papanagnou+ng at hotmail.com> writes:
>> I found a Python sample[*] but I am neither familiar with
>> Python nor with the 'simple_websocket_server' package that
>> is used in that sample code. But the code looks so simple
>> that I'm considering to learn and use Python for the task.
> 
> I've generally used ThreadingServer(SocketServer) for this purpose
> and I think threads are less confusing than async, and performance is
> fine if the concurrency level is not too high.  But, trying to write a
> web server in Python if you don't know Python doesn't seem like a great
> idea, except as a learning project.

I have a couple decades experience with about a dozen programming
languages (not counting assemblers). Asynchronous processing, IPC,
multi-processing, client/server architectures, multi-threading,
semaphores, etc. etc. are concepts that are not new to me.

I'm not, literally, intending to write a web-server. It's a JS
application that is running in (browser based) clients, and the
server is just centrally coordinating the client applications.

My expectation would be that any sophistically designed socket/
web-socket library would not impose any risk. And the intended
server by itself has only very limited requirements; listening to
incoming request, storing some client information, broadcasting
to the attached clients. Basically just (informally written):

  init server
  forever:
    wait for request(s) -> queue
    handle requests from queue (sequentially):
      store specific information from new registered clients
      broadcast some information to all registered clients

It seems to me that multi-threading or async I/O aren't necessary.

I'd like to ask; where do you see the specific risks with Python
(as language per se) and it's (web-socket-)libraries here?

If the web-socket IPC is well supported the algorithmic parts in
Python seem trivial to learn and implement. - Or am I missing
something?

(A brief search gave me the impression that for JS communication
web-sockets would be the method to use. Otherwise I'd just use
basic Unix domain sockets for the purpose and write it, say, in
C or C++ that I already know. But I don't know whether (or how)
plain sockets are used from JS running in a browser. Here I'm
lacking experience. And that lead me to have a look at Python,
since the web-sockets/server examples that I found looked simple.)

Janis



More information about the Python-list mailing list