Re: select(), sending and receiving data



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!"
.



Relevant Pages

  • Port Assignment- OT in a Small Way
    ... 5:RJE - Remote Job Entry ... 18:MSP - Message Send Protocol ... server, Traitor 21, WebEx, WinCrash, NerTe, ... 22:SSH - SSH Remote Login Protocol, RAT: Shaft ...
    (comp.security.misc)
  • Port Assignment- OT in a Small Way
    ... 5:RJE - Remote Job Entry ... 18:MSP - Message Send Protocol ... server, Traitor 21, WebEx, WinCrash, NerTe, ... 22:SSH - SSH Remote Login Protocol, RAT: Shaft ...
    (comp.security.firewalls)
  • Port Assignment- OT in a Small Way
    ... 5:RJE - Remote Job Entry ... 18:MSP - Message Send Protocol ... server, Traitor 21, WebEx, WinCrash, NerTe, ... 22:SSH - SSH Remote Login Protocol, RAT: Shaft ...
    (alt.computer.security)
  • PORT NUMBER AND SERVICES
    ... 5:RJE - Remote Job Entry ... 18:MSP - Message Send Protocol ... server, Traitor 21, WebEx, WinCrash, NerTe, ... 22:SSH - SSH Remote Login Protocol, RAT: Shaft ...
    (comp.security.firewalls)
  • Re: client -server interaction over XML supporting multiple protocols
    ... > NETBEUI to access the server to access the functionalities exposed. ... > server doesnot know in advance which client is using what protocol. ... size of the XML and Xfunctionality will determine the demands ...
    (comp.lang.cpp)