#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Atlanta, GA
    Posts
    5
    Rep Power
    0

    data loss over winsock connection


    i have 2 pretty simple programs, one acting as a server (listening on a certain port on my pc) and another as client (also running on my pc connecting to 127.0.0.1 on the server's port)....

    they connect fine, and i have message boxes set up to show me what data is doing what...it appears that the data string i am trying to SEND to the server is fine, but once the server gets the data it instantly turns it into "????????????????"....

    it also seems that the procedure gets confused as it never sends any data back to the client (which it is supposed to do) and my client program ends up timing out (it has a 30 second timer)....

    here is the data arrival procedure in the server....
    Private Sub wsCom_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    On Error Resume Next
    If bytesTotal > 0 Then
    Dim retData
    Dim TUData As Variant
    Dim logOK As Boolean
    Dim usrName
    Dim usrSrvr
    Dim usrPWd
    Dim usrIpAdd
    Dim addNo

    wsCom(Index).GetData retData
    MsgBox retData
    TUData = Split(retData, "|")
    usrName = TUData(0)
    usrPWd = TUData(1)
    usrIpAdd = wsCom(Index).RemoteHostIP
    usrSrvr = TUData(3)

    'add them to the user que
    lstQueUsr.AddItem usrName & " - " & usrIpAdd & " - " & usrSrvr

    checkLogin usrName, usrPWd, usrIpAdd, usrSrvr, intMax

    End If

    End Sub
    This is the procedure in the Client that sends the data to the server

    Dim cliStr
    cliStr = txtUsrId.Text & "|" & txtUsrPw.Text & "|" & Winsock1.LocalIP & "|" & "mainSrv"
    Winsock1.SendData cliStr
    MsgBox "We are connected and have sent the following data" & vbCrLf & vbCrLf & cliStr
    cmdLogin.Enabled = False
    txtUsrId.Enabled = False
    txtUsrPw.Enabled = False
    thanks for any help on this, its about to drive me insane....
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    St. Louis, MO USA
    Posts
    43
    Rep Power
    12
    I don't have time to try out your code, but I can offer some suggestions.

    1. Outgoing is ok, you're sending a string, so that's simple.
    2. Incoming procedure is where the problem is. Your getting a Byte Array, not a string, so when your code implicitly converts the output from your getdata method in the object call:

    wsCom(Index).GetData retData

    What really happens is, you get something like this in the ByteArray first (in memory only)

    bArray(0) = 0
    bArray(1) = 14
    bArray(2) = 0
    bArray(3) = 32
    ... etc

    Zeros, separated by the chars in Ascii code.

    This is an Array that can probably be decoded using the following code converting FROM unicode to a non-unicode string.

    Dim sOutput as String
    sOutput = StrConv( wsCom(Index).GetData retData, vbFromUnicode )

    Msgbox sOutput

    May work, may not. Just a guess....
    - Chris of Custom Fit Technology
    http://www.customfittech.com

    Access to MySQL Conversion Tool,
    Visual XSLT Conversion Tool

IMN logo majestic logo threadwatch logo seochat tools logo