#๐Ÿ”’ client server application

17 messages ยท Page 1 of 1 (latest)

stuck jacinthBOT
#

Hey @hollow path!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
#

@hollow path

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hollow path
#

wtf

gilded girder
#

@hollow path the code keeps on getting deleted because we filter out the slur in it

hollow path
#

oh my bad

#

xd

#

i forgot to remvoe it

#

gg

#

once a client reconnects, i cant take input and send. anyone knows what i am doing wrong?

import socket
import threading
import time

def receiveData(conn):
    while True:
        try:
            data = conn.recv(1024)
            if not data:
                break
            decodedData = data.decode()
            print(f"Received data: {decodedData}")
        except ConnectionResetError:
            print("connected reset by client.")
            print("waiting for new client")
            break
        except ConnectionAbortedError:
            print("connection aborted.")
            break
        except Exception as e:
            print(f"Error receiving data: {str(e)}")
            break

def sendData(conn):
    while True:
        try:
            if conn:
                userInput = input("what do you want to send? ").strip()
                conn.sendall(userInput.encode())
                time.sleep(3)
        except Exception as e:
            print(f"Error sending data: {str(e)}")
            print("will try to ask for new input again")
            continue
        except KeyboardInterrupt:
            print("dont press ctrl.")
            continue

def ClientHandle(server):
    while True:
        conn, addr = server.accept()
        print(f"New client connected: {addr}")
        t_receive = threading.Thread(target=receiveData, args=(conn,))
        t_send = threading.Thread(target=sendData, args=(conn,))
        t_receive.start()
        t_send.start()

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "192.168.0.148"
port = 6666

server.bind((host, port))
server.listen()

t_new_client = threading.Thread(target=ClientHandle, args=(server,))
t_new_client.start()
t_new_client.join()
#

it was working earlier today. idk what i did to make it not work

gilded girder
hollow path
#

i think i will look at again tmr

#

kinda lost rn

#

could i like make a seperate function taking input then pass a paramter in senddata function

gilded girder
#

yeah, possibly, the main point is that functions need to be careful about when they try and call input()
this is the sort of problem where you'll have to start looking into the world of things like threading synchronisation - threading.Lock might be of interest

stuck jacinthBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.