Invalid Stream Handle, jedoch nur manchmal

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

ozzi789

Betreff: Invalid Stream Handle, jedoch nur manchmal

BeitragFr, Sep 17, 2010 12:28
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi

Wie der Titel schon beschreibt, bekomme ich manchmal diese Fehlermeldung
Etwa 1 von 5 mal passiert dies, immer bei der gleichen Stellen.
Ich hab ka wieso.


Kann mir da jemand helfen

Hab das ganze etwas gekürtzt sodass ihr das testen könnt, einfach beide kurz compilen (den "Server" zuerst, also den unteren code)


Besten Dank Smile

Code: [AUSKLAPPEN]
Global log_file$="log.txt"
Global log_file_handle=0
Global log_full_path$=""
Global serverip$=""
Global connection_stream=""
Global mpwd$="lkb7823lfx902bgt9qlxc834n12389mf"

AppTitle "Agent"

Global string_line$="--------------------------------"

Print "Started"

log_open()
config_open()
connection_server(serverip$)

Print connection_stream

auth()


sendinfo()


While 1
   
    If ReadAvail(connection_stream)>0
    Print ">"+ReadLine(connection_stream)
    EndIf
   
    If Eof(connection_stream)
    Exit
    EndIf
   
     
Wend

sendmessage("quiting!")
close_server()
log_close()
Input


Function auth()
    pwd$=ReadLine(connection_stream)
    Delay(2)
    pwd$=rc4(pwd$,mpwd$)
    Print "SessionPW: "+pwd$
    mpwd_srv$=ReadLine(connection_stream)
    Delay(2)
    If mpwd$<>rc4(mpwd_srv$,pwd$)
        log_action("Server Auth failed!")
        log_close
        close_server
    EndIf
End Function




Function sendinfo()
    sendmessage("SENDINGINFO")
    sendmessage(GetMACAdr())
    sendmessage(GetEnv("COMPUTERNAME"))
    sendmessage(GetEnv("OS"))
    sendmessage(GetEnv("PROCESSOR_ARCHITECTURE"))
    sendmessage(GetEnv("SystemDrive"))
    sendmessage(GetEnv("USERNAME"))
End Function



Function sendmessage (txt$)
Print txt$
    WriteLine(connection_stream,txt$)
    DebugLog "Sending >"+txt$
End Function


Function log_action (action$)
    WriteLine log_file_handle,action$
End Function


Function log_open()

    curdir$=CurrentDir()
    log_full_path$=curdir$+log_file$
   

    If FileType(log_full_path$)=0
        log_file_handle=WriteFile(log_full_patah$)
    Else If FileType(log_full_path$)=1
        log_file_handle=OpenFile(log_full_path$)
    EndIf

    If log_file_handle=0 Notify ("log.txt cant be created!")
   
    SeekFile(log_file_handle,FileSize(log_full_path$))
   
    log_action(string_line$)
    log_action("Starting Agent")
    log_action(CurrentTime()+" "+CurrentDate())

End Function

Function log_close()
    log_action(string_line$)
    log_action ("Closing Agent! "+CurrentTime()+" "+CurrentDate())
    log_action(string_line$)
    log_action("")
    Delay(200)
    CloseFile (log_full_path$)
End Function

Function config_open()
    curdir$=CurrentDir()
   
    config_full_path$=curdir$+"config.dat"
   
    config_handle=OpenFile(config_full_path$)
    If config_handle=0
        RuntimeError("config.dat is missing")
        log_action(string_line$)
        log_action("config.dat is missing. quiting!")
        log_action(string_line$)
    EndIf
    serverip$=ReadLine(config_handle)
    log_action("server is: "+serverip$)
    CloseFile(config_handle)
End Function

Function connection_server(serverip$)
    connection_stream=OpenTCPStream(serverip$,1248)
    If  connection_stream=0
        log_action("Server is unreachable, quiting")
        Delay(10)
        RuntimeError("Server is unreachable, quiting")
    Else
        log_action("Server is reachable, connected i guess")
    EndIf
End Function

Function close_server()
    CloseTCPStream connection_stream
End Function

Function rc4$(s$,key$)
  Local sbox[255], keyh[255]
  For i = 0 To 255
      sbox[i] = i : kptr = kptr + 1
      keyh[i] = Asc(Mid$(key$, kptr, 1))
      kptr = kptr Mod Len(key$)
  Next
  For i = 0 To 255
      j = (j + sbox[i] + keyh[i]) Mod 256
      swap = sbox[i] : sbox[i] = sbox[j] : sbox[j] = swap
  Next
  For x = 1 To Len(s$)
      i = x Mod 256 : j = (j + sbox[i]) Mod 256
      r$ = r$ + Chr$(Asc(Mid$(s$, x, 1)) Xor sbox[(sbox[i] + sbox[j]) Mod 256])
  Next
  Return r$
End Function



Function GetMACAdr$()
    Local cmd$="cmd /c ipconfig /all > "+Chr(34)+CurrentDir()+"temp.txt"+Chr(34)
    ExecFile cmd$
    Delay 500
    Local reader=ReadFile("temp.txt")
    If reader=0 Then Return ""
    Local txt$="",adr$=""
   
    While Not Eof(reader)
        txt$=ReadLine(reader)

        ;;Kürzere, schnellere Abfrage. Allerdings nur für deutsche Windows-Installationen
        ;If Instr(txt$,"Physikalische Adresse")>0 Then
        ;Ausführliche Abfrage, die auf allen Windows-Systemen funktionieren sollte
        If GetStringCount(txt$,"-")=5 Then
            adr$=Trim(Mid(txt$,Instr(txt$,":")+1))
            Exit
        EndIf
    Wend
    CloseFile reader
   

    DeleteFile "temp.txt"
   
    Return adr$
End Function

Function GetStringCount(txt$,search$,casesensitive=True)
    Local index=1
    Local count=0
   
    If Not casesensitive Then
        txt$=Lower(txt$)
        search=Lower(search$)
    EndIf
   
    Repeat
        index=Instr(txt$,search$,index)
        If index=0 Then Exit
        count=count+1
        index=index+Len(search$)
    Forever
   
    Return count
End Function


Code: [AUSKLAPPEN]
Global Timer = CreateTimer(2)
Global mpwd$="lkb7823lfx902bgt9qlxc834n12389mf"
Global pwd$
Global ClientStream

AppTitle "Server"

Type clients
    Field nhandle
End Type

; Server eröffnen
Global Stream = CreateTCPServer( 1248 )
If Stream<>0
    Print "Eröffnet"
Else
    Print "Port blocked [1248] or Server allready running"
EndIf



While Clientstream=0
   ClientStream = AcceptTCPStream( Stream )
   WaitTimer(Timer)
Wend



createpwd()
client_login()
client_info()

While inp$<>"exit"
    inp$=Input(">")
    sendmessage(inp$)
Wend



Function client_info()
    Print "reciving info from client"
    For x=1 To 7
        Print ReadLine(ClientStream)
    Next
End Function



Function sendmessage (txt$)
    WriteLine(ClientStream,txt$)
End Function



Function client_login()
    WriteLine ClientStream,rc4$(pwd$,mpwd$)
    Print "SessionPW: "+pwd$
    WriteLine ClientStream,rc4$(mpwd$,pwd$)
    WriteLine ClientStream,"Hi"
    Print "SENDING"
End Function

Input

; Streams schliessen
If ClientStream Then CloseTCPStream( ClientStream )
CloseTCPServer( Stream )
End


Function createpwd()
    SeedRnd MilliSecs()
    For i=1 To 20+Rnd(1,5)
        pwd$=pwd$+Chr(Rnd(32,125))
    Next
End Function


Function rc4$(s$,key$)
  Local sbox[255], keyh[255]
  For i = 0 To 255
      sbox[i] = i : kptr = kptr + 1
      keyh[i] = Asc(Mid$(key$, kptr, 1))
      kptr = kptr Mod Len(key$)
  Next
  For i = 0 To 255
      j = (j + sbox[i] + keyh[i]) Mod 256
      swap = sbox[i] : sbox[i] = sbox[j] : sbox[j] = swap
  Next
  For x = 1 To Len(s$)
      i = x Mod 256 : j = (j + sbox[i]) Mod 256
      r$ = r$ + Chr$(Asc(Mid$(s$, x, 1)) Xor sbox[(sbox[i] + sbox[j]) Mod 256])
  Next
  Return r$
End Function
0x2B || ! 0x2B
C# | C++13 | Java 7 | PHP 5

Badudel

BeitragSa, Sep 18, 2010 13:51
Antworten mit Zitat
Benutzer-Profile anzeigen
Im Client in der Funktion "log_open" steht:

BlitzBasic: [AUSKLAPPEN]
If FileType(log_full_path$)=0
log_file_handle=WriteFile(log_full_patah$)
Und da ist ein Tippfehler (patah statt path).

Was rate ich da? IDEal, da sieht man das dann schön.

Gruß
Wir werden dem Schwein schon schlachten, auch wenn ihm quiekt.
Zum Teufel mit das Grammatik!

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group