Python Forum
managing SOCK.STREAM digit values - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: managing SOCK.STREAM digit values (/thread-32949.html)



managing SOCK.STREAM digit values - Pillopollo - Mar-18-2021

Hello Everybody.
Beginner and first post here.

i need some help because i can't manage the socket(SOCK.STREAM) object.

the script i'm using is the following:
import socket
import sys

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 3000)
print(f'starting up on {server_address[0]} port {server_address[1]}')
sock.bind(server_address)
sock.listen(1)

while True:
    print('waiting for a connection')
    connection, client_address = sock.accept() #
    try:
        print('client connected:', client_address)
        while True:
            data = connection.recv(1024)
            data = data.decode("utf-8")
            data = data.replace('\n', '').replace('\t','').replace('\r','').replace(';','')
            print(f'received {data}')
            if not data:
                break
    finally:
        connection.close()
i'm sending an ''audio'' signal from PureData(with netsend object) to Python, the values sent are transalted as values from 0 to 99 (is going to a volume value).
and let's say that i'm sending a constant value of 89.
what i get on Python is:

received 89898989
received 89898989
received 898989
received 89898989
..
why i get 4 couples value at the time instead of 2 digits like this?:
received 89
received 89
...
this is what happens when i change the value sent from PureData
received 67676767
received 67676871
received 7274778184
received 87878989
received 89898989
...
any help appreciated.