Can I push on TCP stream socket?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buba
    New Member
    • Nov 2009
    • 2

    Can I push on TCP stream socket?

    It's my first post on the group, I'm not c++ programmer. For last 10 years I did everything except c/c++ (or very little). I find it really difficult, more difficult than I expected. Worst of all I know it really makes sense... But, the question:

    We have two sockets. Server calls socket(), listen(), accept(), client calls socket(), connect(), than send(), server calls recv(), than send(), client... and so on...

    In all examples I can find it's that client requests, than server responds...

    My question is if I will keep the socket open and connected, can I push from the server to the client (without request)? Isn't request/response just a simplification and it doesn't really matter in case of socket? So I can just write to the buffer of connected socket and read it on the other side?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    A (Berkeley) tcp socket is just a bi-directional byte stream, the client or the server can send data any time they choose. And in fact the server is not required to reply to a client request (or vice versa).

    I have written applications where although it is the client that connects it is the server that initiates most communication once the client has authenticated itself.

    Comment

    • buba
      New Member
      • Nov 2009
      • 2

      #3
      Thanks Banfa :). That's what I expected... makes sense :)

      Comment

      Working...