PoC: Harbour ↔ Python via WebSocket (just like Node.js)

Post Reply
User avatar
Otto
Posts: 7020
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

PoC: Harbour ↔ Python via WebSocket (just like Node.js)

Post by Otto »

Hello friends,

after connecting Harbour to Node.js via WebSocket, I will try the next obvious step:

Python can talk to Harbour via WebSocket in exactly the same way.

No tricks.
No frameworks.
No global installs.

✔ bidirectional
✔ stateful
✔ portable
✔ no registry
✔ no global runtime

Harbour ↔ WebSocket ↔ Python is technically just as clean as Harbour ↔ Node.js.

--- Why this works today (and was unthinkable years ago)

Back then (Crystal Reports, COM, DLLs):

  • global runtimes
  • version conflicts
  • mandatory installers
  • hard to support

Today (Node / Python / Harbour):

  • everything runs in user space
  • each runtime is isolated
  • WebSocket is a clear contract
  • processes are replaceable

👉 The operating system is just transport now.

--- Python + WebSocket: typical setup

Python has very stable WebSocket libraries:

  • websockets (async, very common)
  • aiohttp
  • FastAPI (for larger services)
--- Minimal Python WebSocket server

Code: Select all | Expand

# ws_python_server.py
import asyncio
import websockets
import json

async def handler(ws):
    print("client connected")
    async for msg in ws:
        print("RX:", msg)
        data = json.loads(msg)

        if data.get("cmd") == "VERSION":
            reply = {
                "engine": "python",
                "version": "3.12",
                "msg": "hello from python"
            }
            await ws.send(json.dumps(reply))

async def main():
    async with websockets.serve(handler, "127.0.0.1", 8083):
        print("Python WS server on ws://127.0.0.1:8083")
        await asyncio.Future()

asyncio.run(main())

Start with:

Code: Select all | Expand

python ws_python_server.py
--- Harbour side: no change needed

The Harbour WebSocket client:

  • does not know if the backend is Node or Python
  • speaks the same protocol
  • uses the same code

Code: Select all | Expand

ws_send_text( '{ "cmd": "VERSION" }' )
cReply := ws_recv_text()

Reply:

Code: Select all | Expand

{
  "engine": "python",
  "version": "3.12",
  "msg": "hello from python"
}
--- Why this is architecturally strong

You now have:

Code: Select all | Expand

Harbour
   ↔ WebSocket (JSON)
       ↔ Node.js   (SQL, PDF, Web)
       ↔ Python    (AI, ML, statistics)
       ↔ other services

Harbour does not decide how something is done —
only what is needed.

--- When Python makes more sense than Node.js TaskBetter SQL / APIs / PDFNode.js AI / ML / statisticsPython NumPy / PandasPython Web renderingNode.js Prototypingboth

👉 WebSocket makes the language interchangeable.

--- Portable Python: same surprise as Node.js

Yes, Python can also be:

  • portable
  • no installer
  • no registry
  • local folder only

Example:

Code: Select all | Expand

/python
  python.exe
  Lib/
  ws_service.py

Start → works.

Exactly like Node.js.

--- Conclusion

This PoC shows that Harbour can integrate with multiple modern runtimes in a clean, understandable way.

No rewrites.
No global dependencies.
Just a clear interface.
Best regards,
Otto

Post Reply