|
|
Home » U++ Library support » U++ MT-multithreading and servers » How to create sockets that don't block the GUI?
How to create sockets that don't block the GUI? [message #38225] |
Fri, 07 December 2012 13:38  |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
So far I was able to communicate between sockets, but my problem is that when there's intensive processing the GUI locks and I can't interact with it.
I'd like to have a socket in a while(1) loop while having the GUI fully functional.
Any ideas?
|
|
|
|
|
|
|
|
|
Re: How to create sockets that don't block the GUI? [message #38234 is a reply to message #38231] |
Fri, 07 December 2012 17:30   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
Actually what is being sent is a string of char not a line but it is often referred to as "sending a line".
A String has \0 at the end, NUL terminated.
Note in my previous post I have 'lines' as they were separate lines before adding all the char to the buf to be sent/received.
I have a char buf of 3000
I just add the char and only at the end is there \0
Sometime the only thing sent from the client is "+" which is actually '+' \0 or 43 0 or 0x2B 0x0
The server returns the latitude and longitude of the center in the Java app.
For tracking up to 50 objects with lat, lon, alt, ID, etc then all that data for all 50 is added to the char buf then ended with \0.
On the server the \0 means just that, the end.
So if the buf contains 2000 char and then just + \0 is sent the rest of the buf is ignored and not even sent as \0 means THE END.
A better definition would be a C string.
http://stackoverflow.com/questions/10943033/why-are-strings- in-c-usually-terminated-with-0
(Line feed, '\n', 0x0A, 10 in decimal)
So '\n' is just ch = 10;
When that is sent through a socket that is all it is.
How it is dealt with on receiving can be handled.
NULL is same as '\0' which is same as 0x0 or 0
[Updated on: Fri, 07 December 2012 17:53] Report message to a moderator
|
|
|
|
Re: How to create sockets that don't block the GUI? [message #38441 is a reply to message #38241] |
Sat, 15 December 2012 18:40   |
nlneilson
Messages: 644 Registered: January 2010 Location: U.S. California. Mojave &...
|
Contributor |
|
|
What is being sent through a socket is a bunch of character ending with \0.
After it is received it can be parsed into separate lines with \n
Do all of the addition of characters before passing the data to the client to be sent and on the server just pass the whole buffer out to be parsed.
For small amounts of data it can be added and parsed in the client and server.
The \n or \r are just like any other character as far as what is in the buffer or packet sent. If the actual packet size limit is 65536 then there could be many \n or whatever.
The only character that has real significance is \0 which indicates the END of the packet.
Parse what is in the packet outside the server code unless the amount of data is small.
[Updated on: Sat, 15 December 2012 18:50] Report message to a moderator
|
|
|
|
Re: How to create sockets that don't block the GUI? [message #39482 is a reply to message #39480] |
Thu, 21 March 2013 06:57   |
|
Alexander_Ag wrote on Wed, 20 March 2013 21:28 |
lectus wrote on Fri, 07 December 2012 16:38 | So far I was able to communicate between sockets, but my problem is that when there's intensive processing the GUI locks and I can't interact with it.
I'd like to have a socket in a while(1) loop while having the GUI fully functional.
Any ideas?
|
Very interesting topic - can anyone give a sample code with GUI that use TcpSocket as server, i just begin work around sockets.
For example http://www.ultimatepp.org/reference$SocketServer$en-us.html but with GUI.
|
It works the same way as any other time consuming process. You just have to make sure that you call Ctrl::ProcessEvents() from time to time to update the GUI. In case of sockets you might want to lower the timeout, so the loop executes faster and call ProcessEvents in each iteration.
Alternatively, use two separate threads...
Best regards,
Honza
|
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 23:13:37 CEST 2025
Total time taken to generate the page: 0.01114 seconds
|
|
|