2

I'm trying to connect my codes those are written in python and processing(java). python hangs until it gets some data. it makes some problem for me! i use select.select but it hangs again until it gets some data. I am pleased if you help me.

here is my python socket class:

import socket
import select
import time

class client():
    def __init__(self,HOST,PORT):
        self.HOST = HOST              # Symbolic name meaning all available interfaces
        self.PORT = PORT              # Arbitrary non-privileged port
        self.connect()
    def connect(self):
        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.s.bind((self.HOST, self.PORT))
        self.s.listen(1)
        self.conn, self.addr = self.s.accept()
        print('Connected by', self.addr)
        return
    def readData(self):
        do_read = False
        try:
            r, _, _ = select.select([self.conn], [], [])
            do_read = bool(r)
        except socket.error:
            pass
        if do_read:
            # ready to receive
            data = self.conn.recv(1024)
            return data
        return 0

print('hello')
x=client('localhost',5204);
#print('Connected by', addr)
while True:
    data=x.readData();
    if data:
        print(data)
MohammadJavad
  • 21
  • 1
  • 2
  • this link help me to find my answer: https://stackoverflow.com/questions/2719017/how-to-set-timeout-on-pythons-socket-recv-method – MohammadJavad Feb 17 '18 at 08:35

0 Answers0