Creating a server during rendering

I am trying to create a simple server which listen to client every second while rendering in order to retrive position data (BVH format).

from pandac.PandaModules import *
from socket import *
from direct.stdpy import thread
import time

def server(Thread):
    myHost = "localhost"
    myPort = 50007

    s = socket(AF_INET, SOCK_STREAM)    # create a TCP socket
    s.bind((myHost, myPort))            # bind it to the server port
    s.listen(5) 

    print "Waiting Client"
    connection, address = s.accept() # connection is a new socket
    while 1:
            
        data = connection.recv(99999) # receive up to 1K bytes
        print "Client Arrive"
        if not data:
            break
        print "item recive"
    connection.close()              # close socket
    print "Session closed."

The problem is the rendering slow down to 2 fps, am I doing something wrong with threading?

Thanks

add

s.settimeout(.01)

to make the connection timeout fast enough. if you run via loopback this should be more than enough.
edit:dunno if you’r doing something wrong with threading. it looks like some of the code for threading is missing/not posted.

Instead of using thread, is it possible to create server as a task? I had tried that before but it seem the client got refuse by server after a while.

Server:

from pandac.PandaModules import *
from socket import *
from direct.stdpy import thread
import time

def server(task):
    myHost = "localhost"
    myPort = 50007

    s = socket(AF_INET, SOCK_STREAM)    # create a TCP socket
    s.bind((myHost, myPort))            # bind it to the server port
    s.listen(5)

    print "Waiting Client"
    connection, address = s.accept() # connection is a new socket
    while 1:
           
        data = connection.recv(99999) # receive up to 1K bytes
        print "Client Arrive"
        if not data:
            break
        print "item recive"
    connection.close()              # close socket
    print "Session closed."

    return Task.cont
taskMgr.add(server, "server")

Client:

#!/usr/bin/python
import sys
from socket import *
import time

class Main():
    
    def __init__(self):
        
        self.line = []
        
        HOST = 'localhost'        # The localhost
        PORT = 50007              # The same port as used by the server
        s = socket(AF_INET, SOCK_STREAM)
        s.connect((HOST, PORT))
        file = open("test.bvh")   
        fdata=file.read()
        
        s.send(fdata)  
        s.close()
        
while 1:
    Main()

if you really just want to send data over the loopback addres.
i wrote a small example which does exactly that.
https://discourse.panda3d.org/viewtopic.php?t=6530

the part around line 190 in the maze.py might be of intrest. aswell as the face.py

Sorry for the late reply, Thanks for helping me!!!

your settimeout method work perfectly!