Search code examples
pythondjangowebsocketserverclient

Django Websocket Send Text and bytes at sametime


I have client and server in my project. In the client part, the user will upload his own excel file and this file will come to my server for processing. My artificial intelligence python code will run on my server and it will make changes to excel. When every time it changes, I want to send the updated version to the client so that the client can see the change live. Example Let's say I have 10 functions on server side, each function changes some cells in excel(I can get the index of the changed cells). When each function is finished, I will send the changing indexes to the client and these changed places will be updated in the table in the client (C++, Qt).

At first, I made the server with PHP, but calling my artificial intelligence python codes externally(shell_exec) was not a good method. That's why I want to do the server part with python.

  1. Is django the best way for me?

What I've tried with Django: I wanted to send data continuously from server to client with StreamingHttpResponse object, but even though I used iter_content to recv the incoming data on the client, when all the code was finished, all came at once. When I set the chunksize value of iter_content to a small value, I could get it instantly, but it's not a full word. So I decided to use websocket.

I have a problem with websocket; I can't send text and byte data at the same time. When client while uploading the Excel file, I need to send some text data as a parameter to my server.

Waiting for your help thank you!


Solution

  • You can send bytes as hexadecimal string.

    Check this out: binascii hexlify