debugging - Qt: Python tcp client sends data over socket. How to read these bytes with Qt? -


Status: I have a TCP customer created with Qt from Python and TCP server. I try to send bytes with my client, but I can not get the QT server to read these bytes.

Using Python, the customer and server were created, everything works fine except that I can not get any problems with my Python client with the C # server.

Code for the Python client:

  Import socket import system HOST = 'localhost' PORT = 50505: Sock = socket.socket (socket.AF_INET, socket.SOCK_STREAM) Message except socket.error: sys.stderr.write ("[ERROR]% s \ n"% msg) sys.exit (1) Try: sock Message except socket.error: sys.stderr.write ("[ERROR ] (% HOST, PORT) \ n ')  
).

I have tried the Eki lucky / fatal code examples but they are not working. Bytes option is always 0.

So the question is how can I read in my QT application "Hello World!" line? I just need that function when a server emits new connection () signals.

  connect (TCP server, signal (new connection), this, slot (startRead ());   ); In.setVersion (QDataStream :: Qt_4_0); QString ipAddress; If (blockSize == 0) {if (tcpSocket-> bytes available ()  Bytes Available () & lt; blockSize) returns; Qustring NextFortune; In & gt; & Gt; NextFortune; StatusLabel- & gt; SetText (nextFortune); The above fate is from the client example I is from another example below / * four buffers [128] = {0}; QTcpSocket * Client = TCPServer-> gt; Next padding connection (); QDebug () & lt; & Lt; Customers & gt; BytesAvailable (); (Client- & gt; read (buffer, client- & gt; bytes available); QDebug () & lt; & lt; buffer; (for int i = 0; i & lt; 100; i ++); Std :: string sString (buffer); QString qString (sString.c_str ()); statusLabel-> setText (qString);} * /}  

The last part is bad. I tried to do something but I have no clue what I'm doing with Qt :)

< P> You need to read the data as it is available, by your statement, to arrange your code. By startRead () runs until data is available.

I think you are asked to get QTcpServer :: nextPendingConnection to get your tcpSocket startRead () ? If not, then you need to do this.

Just copy your code from your tcpSocket or client to the readyRead signal dread () slot, And check bytes available () and read in that slot.

Whenever new data comes, then this slot will call.

You may also be interested in the disconnect () signal from your TCP socket, to know when it will be time to send the data.


Comments

Popular posts from this blog

php - multilevel menu with multilevel array -

c# - TypeConverter in propertygrid only converts from string, not to -

jQuery UI: Datepicker month format -