Results 1 to 15 of 15

Thread: Unicode Winsock

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Unicode Winsock

    Hi,

    Having trouble with turkish chars.

    When sending data with winsock, simulating a browser....if i type :

    Test Türkçe

    my result is:

    Test T


    This is how winsock treats this string Türkçe : Test+T%FCrk%E7e


    So my question is what do i need to do to to change those special chars to be able to send them with winsock so that the other side(server) can recognize them..??


    Cheers!
    Last edited by batori; Feb 1st, 2011 at 08:08 PM.
    Thanks for helping me out.

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Unicode Winsock

    Don't use String variables.

    As with the intrinsic I/O statements in VB6, the Winsock control translates String data to/from ANSI based on the current codepage.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Unicode Winsock

    so to what do i declare the string variable? hmm
    Thanks for helping me out.

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Unicode Winsock

    If you have your text in a String like S, copy it into a Byte array B before calling SendData:
    Code:
    Dim S As String
    Dim B() As Byte
    
    S = "Your text."
    B = S
    Winsock1.SendData B
    On the receiving end you must use a Byte array with GetData as well.

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Unicode Winsock

    Quote Originally Posted by batori View Post
    This is how winsock treats this string Türkçe : Test+T%FCrk%E7e
    This looks odd though. More like URL-encoding, and the Winsock control does not do that.

    Where do you see this?

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Unicode Winsock

    Quote Originally Posted by batori View Post
    When sending data with winsock, simulating a browser...
    My mistake, I missed that.

    If you want to handle HTTP using the Winsock control you have a lot of extra work to do handling things like various encodings, compression, etc.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Unicode Winsock

    yeah well....i got "Test+T%FCrk%E7e" from an http debugger...its to what winsock encoded the text.

    i was more thinking like a StrConv function or something like that ...
    Thanks for helping me out.

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Unicode Winsock

    No, the Winsock control never URL encodes data. Something else is going on.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Unicode Winsock

    yeah...i forgot to mention i tried to urlencode method too..but with no success

    but here is an interesting solution i tried debuggin with the browser ...

    here is what i get for some chars.
    ü = %C3%BC
    Ü = %C3%9C
    Thanks for helping me out.

  10. #10
    Fanatic Member coolcurrent4u's Avatar
    Join Date
    Apr 2008
    Location
    *****
    Posts
    993

    Re: Unicode Winsock

    you should optionally search for unisock or uniwinsock control, its a custom control written by a forum member with supports Unicode characters out of the box
    Programming is all about good logic. Spend more time here


    (Generate pronounceable password) (Generate random number c#) (Filter array with another array)

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Unicode Winsock

    well now i have another poblem...i cant even load files that have in filename those special chars :/

    i will try to seach for it.
    Thanks for helping me out.

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Unicode Winsock

    You will want to use APIs to open and read the files. Give a quick search for this API: CreateFileW. Tha API will open or create files with unicode support. Along with that API, you'll then use these APIs to get the file size, read the file and close the file: GetFileSize, ReadFile, CloseHandle
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Unicode Winsock

    Or you can try the FSO, which can read text files as either ANSI or Unicode and probably handles Unicode file names as well.

    Assuming any of this really does require Unicode, and isn't just localized ANSI after all.

    Tested this, works file:
    Code:
        Dim FSO As Scripting.FileSystemObject
        Dim strName As String
        Dim lngCount As Long
        
        Set FSO = New Scripting.FileSystemObject
        strName = App.Path & "\Uni" & ChrW$(&H298) & "code.txt"
        With FSO.CreateTextFile(strName, True, True)
            .Close
        End With
        MsgBox "Created file"
        With FSO.OpenTextFile(strName, ForReading, False, TristateTrue)
            Do Until .AtEndOfStream
                .ReadLine
                lngCount = lngCount + 1
            Loop
            .Close
        End With
        MsgBox "Read " & CStr(lngCount) & " lines"

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Re: Unicode Winsock

    Thanks...

    Im trying to use this and i get 0 lines.
    With FSO.OpenTextFile("C:\üÜ çÇ şŞ gG,öÖ.txt", ForReading, False, TristateTrue)
    Do Until .AtEndOfStream
    .ReadLine
    lngCount = lngCount + 1
    Loop
    .Close
    End With
    Thanks for helping me out.

  15. #15
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Unicode Winsock

    String literals in VB6 are in ANSI.

    Notice where I used ChrW$() to insert a Unicode character as part of the file name in my example?

    A more complete example:
    Code:
    Option Explicit
    
    'Encoded version of the posted file name:
    Private Const UnicodeFileName = _
        "\xFC\xDC \xE7\xC7 \u015F\u015E gG,\xF6\xD6.txt"
    
    Private Sub Form_Load()
        Dim FSO As Scripting.FileSystemObject
        Dim UFN As String
        Dim UnicodeText As String
        Dim lngCount As Long
    
        Show
        Set FSO = New Scripting.FileSystemObject
        UnicodeText = UnEsc(UnicodeFileName)
        UFN = App.Path & "\" & UnicodeText
        
        With FSO.OpenTextFile(UFN, ForWriting, True, TristateTrue)
            .WriteLine UnicodeText
            .Close
        End With
        MsgBox "Created file"
        
        With FSO.OpenTextFile(UFN, ForReading, False, TristateTrue)
            Do Until .AtEndOfStream
                UnicodeText = .ReadLine()
                lngCount = lngCount + 1
            Loop
            .Close
        End With
        MsgBox "Read " & CStr(lngCount) & " lines"
        
        'Note that TextBox controls only accept ANSI so VB will perform
        'implicit conversion from Unicode to ANSI here.
        Text1.Text = UnicodeText
        
        'Since TextBox controls only contain ANSI, VB will convert back
        'to Unicode when retrieving values.  However these conversions are
        'not lossless so this comparison can fail!
        MsgBox "Text1.Text == UnicodeText? " & CStr(Text1.Text = UnicodeText)
        
        'Here we use a Unicode-aware Forms 2.0 TextBox control.  No such
        'translation issue here, however the Forms 2.0 Library has
        'redistribution and other issues, so we rarely use it in real
        'programs.
        TextBox1.Text = UnicodeText
        MsgBox "TextBox1.Text == UnicodeText? " & CStr(TextBox1.Text = UnicodeText)
    End Sub
    This example shows how two String values can look the same but not be the same.

    You might read through The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) for more details.
    Attached Files Attached Files

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