Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Async server/client
#1
Hello! I have that 2 small programs 1 for server and 1 for client:


Server:

import socket

serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('localhost', 8089))
serversocket.listen(5) # become a server socket, maximum 5 connections

while True:
    connection, address = serversocket.accept()
    buf = connection.recv(64)
    if len(buf) > 0:
        print buf
        break
Client:
import socket

clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('localhost', 8089))
clientsocket.send('hello')
But that code is syncronous.

How can I write the code to make it (the server side) asyncronous?

Thansk a lot!
Reply
#2
asyncio Protocol and Transports are the classes you need:
https://docs.python.org/3.5/library/asyn...#protocols
https://docs.python.org/3.5/library/asyn...-transport

https://docs.python.org/3.5/library/asyncio-stream.html

You may try Twisted: https://twistedmatrix.com/documents/curr.../examples/

Also, see aiohttp library: https://aiohttp.readthedocs.io/en/stable/web.html - this is the server side
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
Ok, thanks a lot!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  queue for async function python telegram.ext noctious 0 1,513 Jun-11-2023, 02:58 PM
Last Post: noctious
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 679 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  creating python server and client in a pc kucingkembar 4 1,958 Nov-29-2021, 01:37 PM
Last Post: kucingkembar
  Real-Time output of server script on a client script. throwaway34 2 2,011 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  get data from 2 async functions korenron 0 1,202 Sep-22-2021, 08:39 AM
Last Post: korenron
  How to take the tar backup files form remote server to local server sivareddy 0 1,871 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Async requests lukee 0 1,487 Oct-06-2020, 04:40 AM
Last Post: lukee
  Python sockets : Client sending to the server nico31780 0 2,276 May-17-2020, 07:56 PM
Last Post: nico31780
  client-server pictures mcgrim 4 2,919 Oct-25-2019, 09:53 PM
Last Post: micseydel
  Async IO writing to two Different Tables Help TiagoV 0 2,604 Oct-09-2019, 04:45 AM
Last Post: TiagoV

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020