|
|
Home » Developing U++ » U++ Developers corner » U++ needs sockets examples and documentation
U++ needs sockets examples and documentation [message #34810] |
Tue, 13 December 2011 16:19 |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
In my opinion the GUI examples provided with U++ are enough, but it really lacks examples for sockets and web packages.
Yeah, there are a few simple examples using Http. But there's no big example, for example a GUI chat program.
So, it doesn't show how the Web packages work when using the GUI framework.
|
|
|
|
|
|
Re: U++ needs sockets examples and documentation [message #35018 is a reply to message #34810] |
Wed, 28 December 2011 17:09 |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
I know the socket API is simple, but what I really mean is how sockets are used with GUI apps.
For example: Do we need threads? How do make the sockets not block the GUI.
Lots of these questions could be answered with docs and examples (of sockets with GUI).
Also, I'd like to propose something to the U++ Dev Team, if it's not already been done.
In Tcl programming language I can use event-driven programming with sockets and it makes it really simple to not block the GUI and also handle multiple requests.
Here's a sample Tcl code that ilustrates that:
Server.tcl
# Read below to understand these 2 functions
proc readit {chan} {
gets $chan data
puts "We read $data from the socket."
}
proc writeit {chan} {
# Now we can write something to the socket safely.
puts $chan "Some data"
}
proc Serve {chan host port} {
puts "IP $host connected through port $port on channel $chan."
# Here is the interesting part. We set an event to the socket, and when it's readbale it'll execute the readit function and pass the channel as arg.
fileevent $chan readable {readit $chan}
fileevent $chan writable {writeit $chan}
}
# The line below creates a socket server and transfers control to the callback function
socket -server Serve 1234
# The line below waits in a infinite loop (only needed for console app)
vwait forever
Now this code could be used in a GUI app and it would not block the GUI through the use of events. It also handle multiples connects without the use of threads.
I don't know if U++ has anything like this, but it's a good feature to have.
[Updated on: Wed, 28 December 2011 17:11] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Thu May 23 18:24:12 CEST 2024
Total time taken to generate the page: 0.02238 seconds
|
|
|