We help IT Professionals succeed at work.

Sending UNICODE(Double Byte) characters thru winsock

I am facing a problem when i send japanese characters through the windows sockets. When i send single byte characters from the client i am able to recieve the same number at the server end. But when i send double byte characters i dont recieve the same amount of characters the server end. Now since the number of characters dont come in one recv() call i tried to put the recv() in a loop allowing it to fetch the remaining characters from the socket. But there is no value left in the socket and the when the recv() is encountered the next time the application waits there. Now how am i suppposed to suppress this problem

Watch Question

For Win9x compatibility, VB automatically converts all unicode strings into ANSI strings when they are passed to an API call.  The winsock control is ultimately passing the data to an API so VB is converting for you.  You need to change the data type of the data you are sending from a string to a byte array.  VB doesn't automatically screw with byte arrays so the data should be passed correctly.

To keep from having to change your entire app, you can do this very simple conversion just before sending the data.  The next to last line will copy the exact (byte for byte) data from the string variable into the byt variable.  The last list will copy the byte array back into a string variable.

  Dim s As String
  Dim byt() As Byte
  s = "Hello"
  byt = s
  s = byt
Author of the Year 2009

Hi rajkaimal,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    DELETE this question.

rajkaimal, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
DanRollins -- EE database cleanup volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.