This is Bharti Gurav and am working with Winsock for the first time ever. Couldnt recognise where the problem is... Please help. I use following controls:
I have lblstatus( an array of label)
sckListener (an array of winsock)
and txtcontent
The lblstatus is used for displaying msg like "Listening" and "Closed"
The message is displayed as soon winsock starts listening or if it is closed. Since it is an array i can open any number of winsock objects. Now my attempt is to read all the content that is being displayed on to the browser. This is wht i have to achive
Following is the code written. Please help... Looking forward for reply...ASAP
Option Explicit
Private Type ConnectionInfo
FileNum As Integer ' file number of the file opened on the current connection
TotalLength As Long ' total length of data to send (including the header)
TotalSent As Long ' total data sent
FileName As String ' file name of the file to send
DataStr As String
End Type
Private CInfo() As ConnectionInfo
'Private Sub cmdClose_Click(Index As Integer)
'sckListener_Close (Index)
'End Sub
Private Sub cmdConnect_Click()
sckListener(0).LocalPort = 9090
sckListener(0).Listen
DoEvents
If sckListener(0).State = sckListening Then lblstatus(0).Caption = "Listening"
cmdConnect.Enabled = False
End Sub
Private Sub Form_Load()
txtcontent.Text = ""
End Sub
Private Sub sckListener_Close(Index As Integer)
Timer1(Index).Enabled = True
Do
sckListener(Index).Close
DoEvents
Loop Until sckListener(Index).State = sckClosed
lblstatus(Index).Caption = "Closed"
CInfo(Index).FileName = ""
CInfo(Index).FileNum = 0
CInfo(Index).TotalLength = 0
CInfo(Index).TotalSent = 0
lblstatus(Index).Caption = "Closed"
End Sub
Private Sub sckListener_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim k As Integer
For k = 1 To sckListener.UBound
If sckListener(k).State = sckClosed Then Exit For
Next k
If k > sckListener.UBound Then
k = sckListener.UBound + 1
Load sckListener(k)
Load lblstatus(k)
lblstatus(k).Top = (lblstatus(0).Height + 85) * k
lblstatus(k).Visible = True
ReDim Preserve CInfo(k)
Load Timer1(k)
Timer1(k).Enabled = False
Timer1(k).Interval = 1
End If
CInfo(k).FileName = ""
CInfo(0).FileNum = 0
CInfo(k).TotalLength = 0
CInfo(k).TotalSent = 0
sckListener(k).Accept requestID
End Sub
Private Sub sckListener_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim rData As String, sheader As String, ContentType As String
sckListener(Index).GetData rData, vbString
txtcontent.Text = txtcontent.Text & rData
End Sub
Private Sub sckListener_SendComplete(Index As Integer)
If CInfo(Index).TotalSent >= CInfo(Index).TotalLength Then
sckListener(Index).Close
Else
Timer1(Index).Interval = 1
Timer1(Index).Enabled = True
End If
End Sub
Private Sub sckListener_SendProgress(Index As Integer, ByVal bytesSent As Long, ByVal bytesRemaining As Long)
CInfo(Index).TotalSent = CInfo(Index).TotalSent + bytesSent
End Sub
Private Sub Timer1_Timer(Index As Integer)
Timer1(Index).Enabled = False