Re: select(), sending and receiving data
- From: Pascal Bourguignon <spam@xxxxxxxxxxxxxxxx>
- Date: Tue, 27 Dec 2005 01:23:37 +0100
Markus Pitha <markus@xxxxxxxxxx> writes:
> Hello,
>
> Pascal Bourguignon wrote:
>> You need to let your editor indent correctly your code.
>
> Sorry, but when I copy and paste it from the editor in here, it's
> probably much more messy as when I align it on the left side.
I don't understand. You mean you don't read and write news from the
same editor you write programs? Try emacs!
>> You need to reset the fd sets everytime.
>
> Ok
>
>> You need to flush the output.
>
> Ok, I'll keep it in my mind.
>
>> You need to avoid waiting for received packets (unless you mean it, it
>> depends on your protocol).
>
> Actually that's what I want to do. It should be more a Chat server
> instead of a http server.
A chat server doesn't wait for received packets. I mean, block wait.
>> Instead of block reading stdin, you could use select on it too, which
>> would allow you to display incoming packets while the user types in
>> his new message. (Some management of the screen would be needed,
>> ncurses or at least manage raw input to be able to print back the
>> current user input).
>
> That's what I want to try next, but I want to make it step by step.
>
> By the way. Your code seems to work, thanks for it. But there is
> something I don't understand:
> When I connect to the server, I don't get the Welcoming Message, but the
> ">"-sign of the code appears, which means that I'm able to type and send.
Yes, this is time dependant. Either the read or the write is ready
first. (Either a packets arrives nor not before you reach the select call).
If your protocol calls for a first welcome message from the server,
then you must implement a read first (and the protocol probably
specifies some timeout for it to arrive).
> When I write the first sentence and send it, I finally get the welcoming
> message after this first sentence, but moreover, the errormessage
> "recv() in FD_ISSET: Resource temporarily unavailable" appears.
This will always happen, for non-blocking recv, when there is no more
data. The return code and errno sometimes signal mere conditions, not
always errors. Actually, error is too strong a term since it depends
on the caller if a condition should be called an "error".
> Probably there is still something wrong in my code, but I think I can
> find the mistake by myself.
There's nothing wrong in the code. Now you need to do some analysis
and specification work. What protocol do you want to implement, what
user interface, etc.
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Our users will know fear and cower before our software! Ship it!
Ship it and let them flee like the dogs they are!"
.
- References:
- select(), sending and receiving data
- From: Markus Pitha
- Re: select(), sending and receiving data
- From: Pascal Bourguignon
- Re: select(), sending and receiving data
- From: Markus Pitha
- select(), sending and receiving data
- Prev by Date: Re: help needed: remote application
- Next by Date: Re: select(), sending and receiving data
- Previous by thread: Re: select(), sending and receiving data
- Next by thread: Re: select(), sending and receiving data
- Index(es):
Relevant Pages
|