Socket com Python

Asked

Viewed 70 times

-1

Hi, I’d like to ask for help on a project I’m doing. I wonder how I could get a python socket to "lock" a desktop program I made and only release that program for use when the server side allows.

  • Could you give more information about what would be "crash the program"? How did this program? How would the socket communicate with it?

  • This part of the communication is part of the doubt rs Imagine a voting process, with a server side (table table) and the client that is the urn itself. The socket would be to "release the vote" on this other machine.

2 answers

0


Use the normal program communication you have with the server - and put on the server some specific request to stop responding to that client if it is not authorized.

It is not necessary, nor productive, to have a special protocol for this - even if the lock was on the client side, your user could simply edit the program and delete this test.

The customer has to have a user key. The server has to, in each request know the client is responding, and know, with a simple table in the database, or any other data structure you have on the server, whether that client is active and has the permissions for a given access or not. The equivalent of being logged in to a session in the case of a web application.

Anyway, even if your client’s communication with the server is already through pure sockets (which would be unnecessary to begin with - it’s better to use a higher-level protocol to avoid reinventing the wheel), the logic of authorization does not have to be mixed with the logic of receiving messages in the sockets - and yes, in the interpretation of these messages.

0

I believe that by default, sockets are blocking. That is, the function that reads the data coming from the network blocks the current thread waiting for the data to arrive.

Therefore, if you are not using multithreading in your customer, you already have what you want. When you call the "read" function the client program will be locked waiting for the data coming from the server.

In fact it is much more difficult to do otherwise, that is ,non-blocking sockets. Keeping the program running while waiting for network information is much more complex.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.