Can a socket send and receive at the same time python?
Basically I have been working on a simple chat room using socket and thread. In my client I can receive and send messages, my issue is that one comes before another in a loop, so if I am sending a message I will only receive data once I have sent a message. I want it to work like any other chat room, where I could receive a message when I am sending a message, any help will help greatly. This is my basic client: Show
asked Oct 30, 2015 at 10:39
You should keep 2 threads: one for listening and the other for receiving. In your
Adrian Mole 46.1k124 gold badges45 silver badges73 bronze badges answered Oct 30, 2015 at 10:54
SugamSugam 5873 silver badges12 bronze badges One socket may send and receive at the same time but one thread has to only send data and other thread has to only receive data. This way Without threads it would be harder to do this. server.py
Can you send and receive on a socket at the same time?Once connected, a TCP socket can only send and receive to/from the remote machine. This means that you'll need one TCP socket for each client in your application. UDP is not connection-based, you can send and receive to/from anyone at any time with the same socket.
How do you send and receive data using socket in python?Overview:. The send()method of Python's socket class is used to send data from one socket to another socket.. The send()method can only be used with a connected socket. ... . The send() method can be used to send data from a TCP based client socket to a TCP based client-connected socket at the server side and vice versa.. How does python handle multiple socket connections?How to Create Socket Server with Multiple Clients in Python. import socket import os from _thread import * ... . ServerSideSocket = socket. ... . try: ServerSideSocket. ... . def multi_threaded_client(connection): connection. ... . while True: Client, address = ServerSideSocket. ... . import socket ClientMultiSocket = socket.. |