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 opensock()
    Short Opens a connection to any server
    Syntax openSock(cHostAddress : STRING) : INTEGER
    Parameter cHostAddress : is a combination of the URL + ":" + Port under which the server shall be connected to (e.g. "127.0.0.1:1234")
    Return Socket-Handle (1 to 32)
    See also:
    closesock() putsock() getsock()
    Description openSock() opens a new TCP connection to any server and its services. This enables us to provide interfaces to almost any known service of the modern internet (e.g. POP3, IRC, SMTP, IMAP, FTP ...)

    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"}