I like the idea, and while I probably won't go with a dialog box for each connection this is what I do have, individual threads, and I like the global UDT flag idea, as I usually used g_Finished for a specific thread...
So I am going to try to incorporate that - which can be set at the beginning of this function and reset after it's complete...

Code:
'========================================================================================== 'THREAD FOR Sending Data Function SendDataThread(ByVal hTcp As Long) As Long Local hThread As Long Local lResult As Long Thread Create SendDataThreadProc(ByVal hTcp) To hThread Function = hThread End Function '========================================================================================== Function SendDataThreadProc(ByVal hTcp As Long) As Long Local lResult As Long Local lLoop As Long Local lCount As Long Local ErrType As Long Local Header As String Local sBuffer As String Local sPacket As String Local sTmp As String Local lHost As String Incr BBSDown.tcpCount lHost = RemoteIp(ByVal hTcp) sTmp = TimeStamp() & " Connection established from: " & lHost lResult = SendMessage(BBSDown.txtHandle, %LB_ADDSTRING, 0, StrPtr(sTmp)) lResult = SendMessage(BBSDown.lblHandle, %WM_SETTEXT, 0, BBSDown.tcpCount) 'lResult = ListView_SetSelection (BYVAL BBSDown.lblHandle, BYVAL BBSDown.tcpCount) ListView_SetItemState BBSDown.lblHandle, BBSDown.tcpCount, &hFFFFFFFF, %LVIS_SELECTED Or %LVIS_FOCUSED 'Perform a receive-loop until there is no data left (ie, the end of stream) sBuffer = "" sPacket = "" Do Tcp Recv hTcp, 1024, sBuffer sPacket = sPacket & sBuffer If Len(sPacket) > 4096 Then Exit Do 'Buffer overflow prevention ' ErrType = GetLastError() Loop Until sBuffer = "" Or IsTrue Eof(hTcp) Or IsTrue Err sPacket = Left$(sPacket,Len(sPacket)-2) lResult = ParseAndUpdateLogfile(ByVal sPacket,ByVal hTcp) 'Updates window ' <-------------Send data and disconnect-------------> Header = "HTTP/1.1 200" & $CrLf Header = Header & "Server: " & BBSDown.szMine & $CrLf Header = Header & "Date: " & GetPCTimeandDate() & $CrLf Header = Header & "Cache-Control: no-cache" & $CrLf Header = Header & "Connection: close" & $CrLf If IsFalse lResult Then 'html Header = Header & "Content-Type: text/html" & $CrLf Header = Header & "Content-Length: " & Format$(Len(g_BBSDown)) & $CrLf Tcp Send hTcp, Header & $CrLf Tcp Send hTcp, g_BBSDown Else 'jpg Header = Header & "Content-Type: image/jpeg" & $CrLf Header = Header & "Content-Length: " & Format$(Len(g_BBSDownImage)) & $CrLf Header = Header & "Accept-range: bytes" & $CrLf 'or something like that. Tcp Send hTcp, Header & $CrLf Tcp Send hTcp, g_BBSDownImage End If Tcp Close hTcp ' <-------------Send data and disconnect-------------> 'End connection here ErrType = GetLastError() If ErrType <> %ERROR_SUCCESS Then sTmp = TimeStamp() & " Error: " & Format$(ErrType) & " - " & GetLastErrorDescription(ErrType) & " - Remote IP: " & lHost lResult = SendMessage(BBSDown.txtHandle, %LB_ADDSTRING, 0, StrPtr(sTmp)) End If End Function '==========================================================================================
Leave a comment: