#Client stops sending the data when sending it after the first data sent

1 messages · Page 1 of 1 (latest)

chilly karma
#

Yeah so , i am learning socket programming and since I am dumb, I can't figure what's going on so it will be greatful if this get debugged.

#

Client stops sending the data after sending the first data

#

Client stops sending the data when sending it after the first data sent

chilly karma
#

ok wait

#

need file or should I send the code in the blocks?

quick osprey
#

blocks preferably

chilly karma
#

oh ok wait for some seconds

regal badger
#

oh your hello world message isnt receiving?

chilly karma
#

yeah it should be a simple fix

#

let me just

#

ok how to send code blocks

#

I forgot

quartz shardBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

chilly karma
#

is the code visible?

#

this one is for server

#

client

#

@regal badger @quick osprey codes uploaded

quick osprey
# chilly karma

the issue is that there's no loop inside handleClient in server.py so after first message, it exits and doesnt take data from the socket

chilly karma
#

I am using thread and it's under while loop

#

As per my debugging, I think there's nothing wrong with server but I may be wrong

quick osprey
#
def handleClient(conn, addr):
  while True:
    msg = conn.recv()
    print(msg)
    if msg == DISCONNECT_MESSAGE:
      conn.close()
      print("Connection broken")
      return
#

your "accept connection" is in a while loop

#

not receiving messages

#

that loop with the threads just allows multiple clients to connect to the server

chilly karma
#

so I dont need the accept function under the loop?

quick osprey
#

idk... depends
if you only want a client to connect once and then the server stops... then you dont need accept function under a loop

#

but if you want the server to keep accepting new connections, you still want the loop there

chilly karma
quick osprey
#

yeah then leave that as it is
just that the handle client threads need to be in a loop as well to keep reading messages sent

chilly karma
#

but keeping it inside the loop breaks it again

quick osprey
#

what are you doing 😄

#

you just have to put a loop inside handleClient
everything else is fine

chilly karma
#

@quick osprey thanks for the solution, I appreciate it

quick osprey
#

no worries

pallid needle
#

@chilly karma your code will not support the client sending a lot of data simultaneously

chilly karma
#

But thanks to everyone who helped tho appreciate it