Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Attribute VB_Name = "CIA2"
- Option Explicit
- Public Chars As String, HCDChars As String
- Public Function CIA2Connect(ByVal IP As String) As Boolean
- Dim MyTime As Long
- '
- FHZConnectorForm.Socket.Close
- FHZConnectorForm.Socket.RemoteHost = IP
- FHZConnectorForm.Socket.Connect
- MyTime = Int(Timer)
- Do
- DoEvents
- If MyTime > Int(Timer) Then
- MyTime = MyTime - 86400 'catch daychange
- End If
- Sleep 10
- Loop While FHZConnectorForm.Socket.State <> sckConnected And MyTime + 5 > Int(Timer)
- If FHZConnectorForm.Socket.State <> sckConnected Then
- CIA2Connect = False
- Else
- CIA2Connect = True
- End If
- End Function
- Public Function SendCIA2Socket(sData As String, WaitFor As String, Optional CloseConnection As Boolean = True, _
- Optional NoWait As Boolean = False) As Boolean
- Dim MyTime As Long
- Dim RetryCounter As Integer
- Dim i As Integer
- '
- On Error Resume Next
- Chars = ""
- RETRY:
- For i = 1 To Len(sData)
- FHZConnectorForm.Socket.SendData Mid(sData, i, 1)
- DoEvents
- If NoWait = False Then
- Sleep 50
- End If
- Next i
- 'fhzconnectorform.socket.SendData sData
- On Error GoTo 0
- MyTime = Int(Timer)
- Do
- DoEvents
- If MyTime > Int(Timer) Then
- MyTime = MyTime - 86400 'catch daychange
- End If
- Sleep 10
- Loop While InStr(Chars, WaitFor) = 0 And MyTime + 2 > Int(Timer)
- 'Debug.Print Chars
- If InStr(Chars, WaitFor) = 0 Then
- If RetryCounter < 3 Then
- RetryCounter = RetryCounter + 1
- GoTo RETRY
- End If
- SendCIA2Socket = False
- If CloseConnection = True Then
- FHZConnectorForm.Socket.Close
- End If
- Exit Function
- Else
- SendCIA2Socket = True
- If CloseConnection = True Then
- FHZConnectorForm.Socket.Close
- End If
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement