Results 1 to 5 of 5

Thread: Winsock client senddata

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    3

    Post Winsock client senddata

    Hi everybody,

    I have a strange problem.

    I using winsock to telnet to some routers.

    When I have textbox to send command, senddata works. But when I usind field from database, NO!

    There is a script in the attachment!


    cmdConnect works!
    cmdDisconect works!
    But cmdSend NO!



    Please help,
    cholegm
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Winsock client senddata

    Your problem is here:
    Code:
    cmdConnect mtNetwork, mtUsername, mtPassword
    cmdSend (Rs.Fields("TaskType1"))
    cmdDisconnect
    Winsock operates asynchronously, that means that control is passed back to your code immediately the SendData has been executed - not when it has actually sent the data - so you're closing the connection before it's had a chance to send the data.

    You should use the Winsock_SendComplete event, which is triggered when the data has actually been sent, to close the socket.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    3

    Re: Winsock client senddata

    You think something like this?

    Code:
    Public Sub cmdDisconnect()
        If WinsockSendFinish = True Then
        Winsock.Close
        End If
        If Winsock.State = sckClosed Then
        WinsockSendFinish = False
        End If
        
    While Not WinsockSendFinish
            DoEvents
        Wend
        
    End Sub
    
    Public Sub cmdSend(tekst As String)
        broj = 0
        Winsock.SendData Chr(13) & Chr(10)
        Winsock.SendData tekst & Chr(13) & Chr(10)
        WinsockSendFinish = True
    End Sub
    In form_load I put WinsockSendFinish = False

    ...


    And again I have the same problem

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Winsock client senddata

    No, more like this:
    Code:
    Private boSent As Boolean
    
    Private Sub Winsock_SendComplete()
    boSent = True
    End Sub
    
    Public Sub cmdSend(tekst As String)
        broj = 0
        Winsock.SendData Chr(13) & Chr(10)
        boSent = False
        Winsock.SendData tekst & Chr(13) & Chr(10)
        Do Until boSent = True
            DoEvents
        Loop
        Winsock.Close
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2008
    Posts
    3

    Thumbs up Re: Winsock client senddata

    Doogle,

    thanks wery much for help!

    I'am new in this...


    I replace code and try...

    two times do command, and next time no

    I just add to code

    Code:
    Public Sub cmdConfigurationSend()
        Dim ConnectString As String
        ConnectString = Chr$(IAC) & Chr$(DOTEL) & Chr$(ECHO) _
                           & Chr$(IAC) & Chr$(DOTEL) & Chr$(SGA) _
                           & Chr$(IAC) & Chr$(WILLTEL) & Chr$(NAWS) _
                           & Chr$(IAC) & Chr$(WILLTEL) & Chr$(TERMTYPE) _
                           & Chr$(IAC) & Chr$(WILLTEL) & Chr$(TERMSPEED)
        If logovano = False Then Winsock.SendData ConnectString
    End Sub

    And put Sub after connect before login code.

    That code I find in project of some Telnet...
    If I understood well, this make vt100 terminal..

    Now works!!!



    Thanks again!

    Best regards,
    cholegm

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