1

So I am trying to make a program that handles communication between GUI and server using socket library. The problem is that GUI can be randomly closed, so server must abandon the connection. But it seems like instead client_socket.send() just waits forever if GUI stops responding. The code is something like this:

try:
  client_socket.send(pickle.dumps('TEST'))
except Exception as E:
  print("Exception:", E)

What I want server to do is just wait for, say, .5 second then abandon the connection. I hope someone can help me.

Thank you.

1

1 Answer 1

2

From the docs: https://docs.python.org/2/library/socket.html

socket.settimeout(value)

where value is number of seconds to wait.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.