Menu

How to use the TCPStream class

Help
2001-04-02
2001-04-05
  • Anders Backman

    Anders Backman - 2001-04-02

    Hi all.

    I have recently started to look into the Networking functionality of CommonC++.
    I have been using the Threads for a while (Works great by the way).

    Im trying to use the TCPStream and build a client server.

    Im having problems using it. The example (tcp.cpp) is not complete? It seems to me that there is a client missing?

    I have several problems:

    1. If I send a string with:

    tcp<<"Hello world" << endl;

    It will be read on the other side as:

    tcp >> buffer; // Contains "Hello"
    tcp >> buffer; // Contains "world"

    2. How can you check that both sides are active?
    I have tried the setKeepAlive(true) and checking with isConnected() which returns true even if the other side is long gone.

    3. The isPending(SOCKET_PENDING_INPUT,2000) seems to indicate that data is available even if the other side is long gone.

    4. What does endl do for the functionality?
    Will it insert a new-line in the string or will
    it call sync() to send data?

    What Im looking for really, is an example of sending/reading data.

    Is there anyone out there that could help me out?

    Kind regards
    Anders.

     
    • David Sugar

      David Sugar - 2001-04-05

      There actually is a "client" example now found in urlfetch.cpp that uses the URLStream class.

      1.

      You may need to use the getline() method for line oriented parsing.

      2.

      The eof() indicator should show when a remote connection has gone.

      3.

      You can also do a SOCKET_PENDING_ERROR to test the exception status.

      4.

      endl performs a flush and adds '\n'.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.