John - Michael - since you got me on the topic I went ahead and tried this, I like the idea of it but I'm not getting my %FD_READ
If I do a CASE ELSE where %FD_READ is at, I get 4 "Msgbox"'s (I use those for debugging)....the browser says "Waiting for reply.."....
I do record a connection, I do get as far as the INITDIALOG in the modeless dialog box....but that's it..
If I do a CASE ELSE where %FD_READ is at, I get 4 "Msgbox"'s (I use those for debugging)....the browser says "Waiting for reply.."....
I do record a connection, I do get as far as the INITDIALOG in the modeless dialog box....but that's it..
Code:
This first bit of code is from my main modal dialogProc call back function: g_nServertcp = FreeFile Tcp Open Server Addr nServerIP Port g_Port As g_nServertcp TimeOut g_TimeOut If Err Then sTmp = "Couldn't create socket!" Control Set Text CbHndl,%IDLABEL1, sTmp Else 'What's the next TCP Count Tcp Notify g_nServertcp, Accept To g_hDlg As %TCP_ACCEPT sTmp = "Listening on " & g_ServerIP & ":" & Format$(g_Port) Control Set Text CbHndl,%IDLABEL1, sTmp End If Function = %TRUE Case %TCP_ACCEPT Select Case Lo(Word, CbLParam) Case %FD_ACCEPT 'Create the new thread here Incr tcpCount Call CreateNewConnectionThread(tcpCount) Control Set Text CbHndl,%IDCONNLABELTL, Format$(tcpCount,"") Function = %TRUE End Select Case %WM_DESTROY Tcp Close g_nServertcp KillTimer CbHndl, %IDT_TIMER1 Shell_NotifyIcon %NIM_DELETE, ti DestroyIcon ti.hIcon '============================================<tcpThreadProc>=============================================================== Function CreateNewConnectionThread(ByVal tcpCount As Long) As Long Local hThread As Long Local lResult As Long Thread Create ConnectionThreadProc(ByVal tcpCount) To hThread Thread Close hThread To lResult 'WaitForSingleObject hThread,%INFINITE Function = hThread 'grab thread handle to close prematurely and properly if need be. End Function '========================================================================================== Function ConnectionThreadProc(ByVal tcpCount As Long) As Long Local tDlg As Long Local lResult As Long Dialog New 0, "",,, 1,1, %WS_POPUP Or %WS_DLGFRAME To tDlg 'modeless Dialog Show Modeless tDlg Call ConnectProc To lResult End Function '========================================================================================== CallBack Function ConnectProc() As Long Local sBuffer As String Local sPacket As String Local Header As String Static hTcp As Dword Local lHost As String Local lResult As Long Select Case CbMsg Case %WM_INITDIALOG hTcp = %INVALID_SOCKET hTcp = FreeFile Tcp Accept g_nServertcp As hTcp Tcp Notify hTcp, Recv Close To CbHndl As %TCP_ECHO Function = %TRUE Case %TCP_ECHO Select Case Lo(Word, CbLParam) Case %FD_READ If hTcp <> %INVALID_SOCKET Then 'Grab client IP and insert here lHost = RemoteIp(ByVal hTcp) AppendTextToWindow g_txtHandle, TimeStamp() & " Connection established from: " & lHost ' 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 Loop Until sBuffer = "" Or IsTrue Eof(hTcp) Or IsTrue Err sPacket = Left$(sPacket,Len(sPacket)-2) & String$(50,"-") lResult = ParseAndUpdateLogfile(ByVal sPacket,ByVal hTcp) 'Updates window ' <-------------Send data and disconnect-------------> If IsFalse lResult Then 'html Header = "HTTP/1.1 200" & $CrLf Header = Header & "Server: " & g_szMine & $CrLf Header = Header & "Date: " & GetPCTimeandDate() & $CrLf 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 & "HTTP/1.1 200" & $CrLf ' Header = Header & "Last-Modified: " & GetFileDateandTime(g_BBSDownImageFile) & " GMT" & $CrLf Header = Header & "Server: " & g_szMine & $CrLf Header = Header & "Date: " & GetPCTimeandDate() & $CrLf 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. Header = Header & "Connection: close" & $CrLf Tcp Send hTcp, Header & $CrLf Tcp Send hTcp, g_BBSDownImage End If Tcp Close hTcp hTcp = %INVALID_SOCKET Dialog End CbHndl,%TRUE ' <-------------Send data and disconnect-------------> 'End connection here End If Case %FD_CLOSE Tcp Close hTcp hTcp = %INVALID_SOCKET End Select End Select End Function '==========================================================================================
Comment