none
Trying to use Winsock control in Microsoft Access Database Form RRS feed

  • Question

  • I'm trying to create a telnet session within my microsoft access form.  I included the microsoft winsocket control and some text boxes to place the recieved data.  The problem I'm having is I recieve data but it is all scrambled like ÿþ%ÿý and it doesn't take any of my data I'm entering.  The current telnet software I'm using is using VT101 emulation if that might have something to do with the scrambled info, but I dont want to use this software and Access.  I would like to keep it all in one application if possible.  I just need some help where I might be going wrong or any other idea's.  Here is a sample of the code I'm using. 

     

    Option Explicit
          Const EchoPort = 23

          Private Sub cmdConnect_Click()
             Dim temp As String
             temp = InputBox$("Enter a server name...", _
                    "Connect to the Echo Service", Winsock1.RemoteHost)
             If temp <> "" Then
             If Winsock1.State <> sckClosed Then Winsock1.Close
                Winsock1.RemoteHost = temp
                Winsock1.RemotePort = EchoPort
                Winsock1.LocalPort = 0
                Winsock1.Connect
             End If
          End Sub

          Private Sub cmdDisconnect_Click()
             If Winsock1.State <> sckClosed Then Winsock1.Close
             cmdConnect.Enabled = True
             cmdConnect.SetFocus
             cmdDisconnect.Enabled = False
            
          End Sub

          Private Sub cmdEcho_Click()
             Text1.SetFocus
             Winsock1.SendData Text1.Text
             Text2.SetFocus
          End Sub

          Private Sub Winsock1_Close()
             If Winsock1.State <> 0 Then Winsock1.Close
          End Sub

          Private Sub Winsock1_Connect()
             Text2.SetFocus
             cmdConnect.Enabled = False
             cmdEcho.Enabled = True
             cmdDisconnect.Enabled = True
          End Sub

          Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

             Dim temp As String
             temp = String(bytesTotal, "*")
             Winsock1.GetData temp, vbString, bytesTotal
             Text2.SetFocus
             Text2.Text = temp
             cmdEcho.Enabled = True
          End Sub

          Private Sub Winsock1_Error(ByVal Number As Integer, _
                                     Description As String, _
                                     ByVal Scode As Long, _
                                     ByVal Source As String, _
                                     ByVal HelpFile As String, _
                                     ByVal HelpContext As Long, _
                                     CancelDisplay As Boolean)
             MsgBox "Error: " & Number & vbTab & Description, vbOKOnly, _
                    "Winsock Control 1 Error"
             CancelDisplay = True
          End Sub

    Wednesday, August 23, 2006 12:17 AM

Answers

  • How is the data being encoded?  Are you being sure to decode the data in the same way?  For example if strings are encoded using UTF8, but you treat incoming byte streams as ASCII you would get such "garbled" data
    Monday, October 23, 2006 3:10 AM

All replies

  • How is the data being encoded?  Are you being sure to decode the data in the same way?  For example if strings are encoded using UTF8, but you treat incoming byte streams as ASCII you would get such "garbled" data
    Monday, October 23, 2006 3:10 AM
  • No the only code I'm using is above, thats as far as I've been able to get.  Could you give me an example on how to decode the strings?
    Tuesday, October 24, 2006 2:30 AM
  • I was encountering the same problem trying to use the winsock control to send a message from an Access application.  The send was sucessful, but the receiving app displayed garbage.  The following code fixed the problem.

    Message2SendTxt.SetFocus
    Mssg = Message2SendTxt.Text
    TcpSkt.SendData Format(Mssg)

    Apparently Acess deals with all controls and variables as UTF16 (not 8).

    Wednesday, November 1, 2006 11:28 PM
  • It's not grabbled info, it's a telnet command.  ÿþ%ÿý  - (255, 254, 37, 253) - (IAC, DONT, ?, IAC, DO ) - (Interpret as command, dont, ?, Interpret as command, do, left off part of message? ) 

    I dont have my stuff in frt of me so i don't know what "%" is and it looks like you may have left off part of the message.  Basicly it's trying to set the parameters of the session, ie (echo, timing mark, window size, terminal speed etc).  Although this is diffently not a complete resoucre there is a little info at. http://support.microsoft.com/kb/231866.    Probably better off just echoing everything back and after a few messages it will get the message that you dont understand and just go into a defualt session.  Then you'll get what your expecting.

    Friday, December 9, 2011 2:23 PM