Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: stupid question about sending/receiving at the same time.  (Read 16067 times)

0 Members and 1 Guest are viewing this topic.

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
stupid question about sending/receiving at the same time.
« on: April 11, 2008, 06:58:17 pm »
Hi.
I know this might sound very retarded, but I tried finding some good tutorials and they always end, before questions as this arise.
I would like to have a 2client 1server system.
Now the server sends packages from one client to another.
Now I would like to be able to send stuff from one client, while I'm still listening for incoming packages.
Well, one could argue "why should you care.. just finish sending and then read what has come inbetween" but unfortunably single packages will melt together to a single big one if I try it this way..
So I tried using two threads one always listening, another the one who has to send the stuff.. (should work- thats what duplex is for, isn't it? besides I'm just using the loopback...) well, it won't work.. somehow, the server complains that the connection was ended / Client.Receive returns with !=sf::Socket::Done. (I just tested having a second thread besides the mainthread that will send stuff)
Any suggestions what to do? Is there a better way doing this, maybe using two ports?? (sounds VERY dump to me..) or is there anything I have to take care of if I want to use one port together with two threads thread?? maybe having a mutex on the send(), so that send() cannot be interupted?? Maybe some links to some more advanced tutorials?
thx in advance.. tgm

*edit* Well, one could prevent the"melting" with sending a size information in the beginning of an package..
the best solution would be a possibility to fast check wether there is any input in the input buffer, or not..