Mit Browser auf Script connecten (TCP)

  • Ich hab da ma ne kleine Frage ^^
    Es geht um - klar - TCP-Verbindungen.
    Ich hab mir mal was kleines zum Testen geschrieben:

    [autoit]

    TCPStartup()
    $listen = TCPListen( @IPAddress1, 6667 )
    $acc = -1
    Do
    $acc = TCPAccept( $listen )
    Until $acc <> -1
    Sleep( 50 )
    $r = TCPRecv( $acc, 2048 )
    If $r <> '' Then
    MsgBox( 0, '', $r )
    EndIf
    TCPShutdown()

    [/autoit]

    Geh ich jetzt mit Firefox auf <meineIP>:6667
    verbindet sich FF mit meinem 'Script'.
    Die Frage ist jetzt:
    Kann ich mir das irgendwie zu Nutze machen ?
    Irgendwie HTML an FF senden oder so ?
    Ich habs mit einfachen TCPSend probiert, scheint nicht so einfach zu funktionieren ;)

    Wenn jemand noch ne Idee hat - immer her damit =)

    mfg limette

    There are only 10 types of people in the world:
    Those who understand binary - and those who don't.

    Einmal editiert, zuletzt von limette (20. März 2008 um 19:53)

  • Hm...
    dann geht doch die Grundidee verloren ^^
    Ich möcht ja direkt auf mein Script, und nicht über son
    'anderes Programm'..
    Es geht mir ja um die Verbindung
    Script <-- Internet --> Firefox
    und nicht
    Script <--> Programm <-- Internet --> Firefox

    Denn ne Verbindung kriegt der ja auch hin, und Firefox sacht ja auch erst
    'Server nicht gefunden', wenn mein Script sich beendet / die Verbindung kappt.
    Möchte dieses 'Xampp' sozusagen.. imitieren =)
    Oder wie auch immer,...
    Zumindest versuchen, ein 'Hallo' oder so an das andere Ende zu senden. ^^

    mfg limette

    There are only 10 types of people in the world:
    Those who understand binary - and those who don't.

  • Hier ist ein Bsp-Server: Gar net so schwer :)

    Spoiler anzeigen
    [autoit]

    #include <String.au3>
    ;===============================================================================
    ;
    ; Description: Mini-WebServer mit AutoIt
    ; Author(s): Prog@ndy, anhand von
    ; http://de.wikipedia.org/wiki/Hypertext…TTP-Statuscodes
    ; http://www.freevbcode.com/ShowCode.Asp?ID=1294
    ;
    ;===============================================================================
    ;

    [/autoit] [autoit][/autoit] [autoit]

    TCPStartup()
    $x = ""
    $listen = TCPListen( @IPAddress1, 6667 )

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1 ; Beliebigoft Seiten ausgeben :)
    $acc = -1
    Do
    $acc = TCPAccept( $listen )
    Until $acc <> -1
    Sleep( 50 )
    $r = TCPRecv( $acc, 2048 )
    If $r <> '' Then
    ;MsgBox( 0, '', $r )
    ;~ ConsoleWrite(@lf & '------------------------------------' & @LF)
    ;~ ConsoleWrite($r)
    ;~ ConsoleWrite(@LF & '------------------------------------' & @LF)
    EndIf
    $x = _GetTextToSend($r)

    [/autoit] [autoit][/autoit] [autoit]

    TCPSend($acc,$x)
    ConsoleWrite(@lf & '------------------------------------' & @LF)
    ConsoleWrite($x)
    ConsoleWrite(@LF & '------------------------------------' & @LF)
    TCPCloseSocket($acc)

    [/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func OnAutoItExit() ; Beim Beenden von AutoIt
    TCPShutdown()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _GetTextToSend(ByRef $r)
    $path = _StringBetween($r,'GET ', ' HTTP')
    Select
    Case @error
    Return ""
    Case $path[0] = '/' Or StringInStr($path[0],'index.htm')

    $x = 'HTTP/1.0 200 OK' & @CRLF & _
    'Date: Fri, 13 Jan 2006 15:12:48 GMT' & @CRLF & _
    'Last-Modified: Tue, 10 Jan 2006 11:18:20 GMT' & @CRLF & _
    'Content-Language: de' & @CRLF & _
    'Content-Type: text/html; charset=utf-8' & @CRLF
    $x = $x & '<html>' & @CRLF
    $x = $x & "" & @CRLF
    $x = $x & '<head>' & @CRLF
    $x = $x & '<style>' & @CRLF
    $x = $x & 'a:link {font:8pt/11pt verdana; color:red; text-decoration:none}' & @CRLF
    $x = $x & 'a:visited {font:8pt/11pt verdana; color:red; text-decoration:none}' & @CRLF
    $x = $x & 'a:hover {font:8pt/11pt verdana; color:red; text-decoration:underline}' & @CRLF
    $x = $x & '</style>' & @CRLF
    $x = $x & '<meta HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">' & @CRLF
    $x = $x & '<title>HTTP 404 Not Found</title>' & @CRLF
    $x = $x & '</head>' & @CRLF
    $x = $x & "" & @CRLF
    $x = $x & '<body bgcolor="#FFFFFF">' & @CRLF
    $x = $x & '<hr>' & @CRLF
    $x = $x & '<a href="index.html"><font size="2"><b>Index</b></font></a>&nbsp;&nbsp;&nbsp;&nbsp;' & @CRLF
    $x = $x & '<a href="cats.loc"><font size="2"><b>Katzen</b></font></a>' & @CRLF
    $x = $x & '<hr>' & @CRLF
    $x = $x & '</body>' & @CRLF
    $x = $x & '</html>' & @CRLF
    Case StringInStr($path[0],'cats.loc')
    $x = 'HTTP/1.0 302 Moved Temporarily' & @CRLF & _
    'Date: Fri, 13 Jan 2006 15:12:44 GMT' & @CRLF & _
    'Location: http://de.wikipedia.org/wiki/Katzen' &@CRLF
    Case Else

    $x = ""

    $x = $x & '<html>' & @CRLF
    $x = $x & "" & @CRLF
    $x = $x & '<head>' & @CRLF
    $x = $x & '<style>' & @CRLF
    $x = $x & 'a:link {font:8pt/11pt verdana; color:red; text-decoration:none}' & @CRLF
    $x = $x & 'a:visited {font:8pt/11pt verdana; color:red; text-decoration:none}' & @CRLF
    $x = $x & 'a:hover {font:8pt/11pt verdana; color:red; text-decoration:underline}' & @CRLF
    $x = $x & '</style>' & @CRLF
    $x = $x & '<meta HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">' & @CRLF
    $x = $x & '<title>HTTP 404 Not Found</title>' & @CRLF
    $x = $x & '</head>' & @CRLF
    $x = $x & "" & @CRLF
    $x = $x & '<body bgcolor="#FFFFFF">' & @CRLF
    $x = $x & '<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b><font color="#FF0000">The' & @CRLF
    $x = $x & ' page cannot be found </font></b></font></p>' & @CRLF
    $x = $x & '<p>&nbsp;</p>' & @CRLF
    $x = $x & '<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">The page you are' & @CRLF
    $x = $x & ' looking for might have been removed, had its name changed, or is temporarily' & @CRLF
    $x = $x & ' unavailable. </font></p>' & @CRLF
    $x = $x & '<p align="center">&nbsp;</p>' & @CRLF
    $x = $x & '<p align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif" color="#0000FF"><i><font color="#000000">HTTP' & @CRLF
    $x = $x & ' 404 - File not found</font></i></font></p>' & @CRLF
    $x = $x & '</body>' & @CRLF
    $x = $x & '</html>' & @CRLF & @CRLF & @CRLF
    EndSelect
    Return $x
    EndFunc

    [/autoit]
  • Wow, danke,
    funktioniert =)

    Tja, den wirklich wichtigen Teil bei Wiki hab ich da wohl übersehen ^^

    mfg limette

    There are only 10 types of people in the world:
    Those who understand binary - and those who don't.