Results 1 to 3 of 3

Thread: winsock - problm receiving packets

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    2

    winsock - problm receiving packets

    Hi All,

    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

    End Sub



    Attached herewith is the looknfeel of the form...
    Attached Images Attached Images  

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: winsock - problm receiving packets

    I see a few unnecessary things in your code...

    But what kind of program are you making?

    What does this mean: "Now my attempt is to read all the content that is being displayed on to the browser."?

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: winsock - problm receiving packets

    use code tags when posting code

    click the Code icon (white box with the word Code inside it) Paste your code.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width