Deutsch English
Alphabetical index
Array functions
CGI functions
Data types
Date functions
Debugging
Fulltext functions
Language elements
Numerical functions
Operators
Other functions
Ramtext functions
Selecting
Socket functions
  • closesock()
  • getsock()
  • opensock()
  • putsock()
  • server()
    Statistical functions
    Stream functions
    String functions
    System functions
    Table functions
    Text functions
    Home    Overview    Search    Impressum    Contact    Members
    Topic complex Socket functions
    Function getsock()
    Short Receives data from an open TCP connection
    Syntax getSock(socket : INTEGER; VAR p : { CHAR[{offset}] | BYTE[{offset}] }; maxchars : INTEGER) : INTEGER
    Parameter socket : handle returned by openSock()
    p : array of type CHAR or BYTE
    offset : field index from which on the incoming data will be stored
    maxchars : Bytes to be read
    Return Number of bytes read at all
    See also:
    opensock() closesock() putsock()
    Description getSock() stores all incoming data in an array.
    Data send via TCP/IP normally gets splitted into packets of the same size (often 1492 Bytes). getSock() only reads in the data that is already waiting in an internal buffer. Packets that belong to the same data block but arrive only milliseconds later won't be read. To prevent this you can read from the socket in a loop until the expected number of bytes has been read.

    Example:
    while nReadBytes := nReadBytes + getSock(s, a[nReadBytes], nBytesToRead) < nBytesToRead do nBlocksRead++ end
    


    This loop reads from the socket until nBytesToRead have been read (nReadBytes)

    Example 1: SMTP-Client

    A SMTP Client

    PROCEDURE send_str(s : INTEGER; l : STRING);
    VAR p : CHAR[1000];
      p[0]:=l+^M+^J; PutSock(s,p,length(l)+2)
      cgiwriteln('> '+l)
    ENDPROC
    PROCEDURE recv_str(s : INTEGER) : STRING;
    VAR p : CHAR[1000];
    VAR i : INTEGER;
    VAR res : STRING;
      nloop(i,GetSock(s,p,1000)-1,res:=res+p[i]);
      RETURN res
    ENDPROC
    
    PROCEDURE Main;
    VAR p : CHAR[1000];
    VAR i : INTEGER;
      cgiclosebuffer;
      cgiwriteln('content-type: text/plain');
      cgiwriteln('');
      IF i:=OpenSock('mail.tdb-engine.de:25') THEN
        cgiwriteln(recv_str(i));
        send_str(i,'HELO mail.tdb.de');
        cgiwriteln(recv_str(i));
        send_str(i,'MAIL FROM:test@tdb-engine.de');
        cgiwriteln(recv_str(i));
        send_str(i,'RCPT TO:test2@tdb-engine.de');
        cgiwriteln(recv_str(i));
        send_str(i,'DATA')
        cgiwriteln(recv_str(i));
        send_str(i,'Das ist ein kleiner Test.');
        send_str(i,'Und das ist die zweite Zeile');
        send_str(i,'.');
        cgiwriteln(recv_str(i));
        send_str(i,'QUIT');
        cgiwriteln(recv_str(i));
        CloseSock(i)
      ELSE
        cgiwriteln('done.')
      END
    ENDPROC
    


    User comments:
    Write a comment:
    Name
    EMail
    Subject
    Text (Switch mode)

    Choose between
    the normal and the
    advanced editor.
    The advanced editor
    runs in IE 5+ and
    Mozilla 1.4+ only
    SPAM-Protection Please enter tdbengine in this field.

    tdbengine chat
    irc.tdbengine.org
    #tdbengine

       Copyright © 2003-2004 tdb Software Service GmbH
       Alle rechte vorbehalten. / All rights reserved
       Last changed: 21.10.2004
    {Fehler für :execmacro{execmacro="sessionspy"}