|
|
Home » U++ Library support » U++ MT-multithreading and servers » Socket in a sock
|
|
Re: Socket in a sock [message #17539 is a reply to message #17528] |
Tue, 19 August 2008 20:22   |
Paco
Messages: 4 Registered: June 2008 Location: Spain
|
Junior Member |
|
|
Thank's a lot captainc about your quick answer, I have read every post coming from you in this topic.
I am not sure if I need only one socket or at least 2 are needed as only few caracters have to be sent to the server.
My application is not a server, is a client that needs to connect to the server, wait for a login, then send 5 caracters and from now continuosly wait listening while the server sends packets of caracters, as they arrive the application has to detect the arrival, extract these caracters from the listening socket buffer and update a string that serves to update a DocEdit widget.
All this work has to be made without interrupting the other application works, like logging contacts to a database, moving a rotor antenna via com port, etc. not a continuos work, maybe a TimerCallback is the better option to read the buffer socket every 500 milliseconds
If you can use telnet, create a connection via TCP/IP with a server "dx.ea7urc.org" port 41112, as the server asks for login type "ea7cdu" (my radioamateur call) and then watch the telnet window (and suppose it is a DocEdit widget) for a few minutes, you will see what I mean. The application has to reproduce the telnet behavior.
If you can spend a few minutes you will teach me about to reproduce this behavior and I will thank you very much.
Hope to read you soon... Thank's again...
|
|
|
Re: Socket in a sock [message #17541 is a reply to message #17539] |
Tue, 19 August 2008 22:13  |
captainc
Messages: 278 Registered: December 2006 Location: New Jersey, USA
|
Experienced Member |
|
|
Quote: | All this work has to be made without interrupting the other application works, like logging contacts to a database, moving a rotor antenna via com port, etc. not a continuous work, maybe a TimerCallback is the better option to read the buffer socket every 500 milliseconds
|
You will need to thread the outgoing connection. What I would do is create a class that would handle outgoing connections (make the connection and read from the buffer) and use the U++ Thread to run a class method. Have that thread run a loop checking for new information on the socket. When it receives information, it could update the Gui. Meanwhile, it would not block the program from doing other things, and the thread would terminate after the function exits (on socket close). You have to be careful with the architecture in this scenario with threading and race conditions though. For example, what if you want to close the program while it is listening for connections (thread running)? How do you end the thread and close the socket? You probably will need to use shared resources and locking in this situation, In this case I would look into making a thread-safe class method that would close the socket and have the function that is running in the thread finish/exit if the socket is closed.
Also, remember that BSD socket connections close when both sides close the socket. The close message that is sent is acknowledged by the other side to officially close the connection.
Sorry I cannot check out the telnet site right now, but I might be able to get to it in a bit.
[Updated on: Tue, 19 August 2008 22:14] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue Apr 29 01:38:46 CEST 2025
Total time taken to generate the page: 0.01048 seconds
|
|
|