Attribute VB_Name = "LanSend"
Option Explicit

'----------------------------------------------------------
'  Function     : TcpSend
'  Return value :
'  Argument     :
'  Feature      :
'  Description  :
'  Remarks      :
'----------------------------------------------------------
Sub TcpSend(PJIndex As Integer)

    Dim LogData As String
    'Dim SockNo As Integer
    
    If (LanForm.TCP(PJIndex).State = sckClosed) Then
        LanForm.TCP(PJIndex).RemoteHost = PJInfo(PJIndex).Connection.Network.IPAddress
        LanForm.TCP(PJIndex).RemotePort = PJInfo(PJIndex).Connection.Network.PortNo
        LanForm.TCP(PJIndex).LocalPort = 0
        LanForm.TCP(PJIndex).Connect
        LanForm.TimeoutTimer(PJIndex).Interval = TcpTimeoutTime
        LanForm.TimeoutTimer(PJIndex).Enabled = True
        Queue(PJIndex, QueueRP(PJIndex)).Status = QS_CONNECTING
        LogData = "TCP(" & CStr(PJIndex) & ")_Connect:" & LanForm.TCP(PJIndex).RemoteHost
        Call LogFileWrite(LogData)
    ElseIf (LanForm.TCP(PJIndex).State = sckConnected) Then
        Queue(PJIndex, QueueRP(PJIndex)).Status = QS_GO
        LanForm.TCP(PJIndex).SendData Queue(PJIndex, QueueRP(PJIndex)).SendData
        LogData = "TCP-Send(" & CStr(PJIndex) & "):" & CharConvertB(Queue(PJIndex, QueueRP(PJIndex)).SendData, CInt(Queue(PJIndex, QueueRP(PJIndex)).SendDataLen))
        Call LogFileWrite(LogData)
        LanForm.TimeoutTimer(PJIndex).Interval = TcpTimeoutTime
        LanForm.TimeoutTimer(PJIndex).Enabled = True
    End If
    
End Sub
