Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Reg to Unicode and MBCS problem in socket programing

Reg to Unicode and MBCS problem in socket programing

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpsysadmin
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rrthangavel
    wrote on last edited by
    #1

    Hai friends, i'm working with client server model socket programing using VC++. it has MFC SOCKET in client side and WIN32 SOCKET in server console application. i'm having proplem with receiving the strings in server side. i displayed part of code here Client Side Coding: UpdateData(1); CSocket client; client.Create (); CString sendstr; sendstr="Hello"; client.Connect ("127.0.0.1",2500); int len=sendstr.GetLength (); int sent= client.Send(LPCTSTR(sendstr),len); UpdateData(0); Server side coding: char recvbuf[32]="" ; int bytesRecv = recv( server, recvbuf, 32, 0 ); printf( "Bytes Recv: %d\n", bytesRecv ); recvbuf[bytesRecv]=NULL; printf("%S",recvbuf); if i run the code i get 5 in bytesRecv correctly.. but in recvbuf buffer three letters only available... like "hel" please help me l'm waiting for u... :^)

    C M A 3 Replies Last reply
    0
    • R rrthangavel

      Hai friends, i'm working with client server model socket programing using VC++. it has MFC SOCKET in client side and WIN32 SOCKET in server console application. i'm having proplem with receiving the strings in server side. i displayed part of code here Client Side Coding: UpdateData(1); CSocket client; client.Create (); CString sendstr; sendstr="Hello"; client.Connect ("127.0.0.1",2500); int len=sendstr.GetLength (); int sent= client.Send(LPCTSTR(sendstr),len); UpdateData(0); Server side coding: char recvbuf[32]="" ; int bytesRecv = recv( server, recvbuf, 32, 0 ); printf( "Bytes Recv: %d\n", bytesRecv ); recvbuf[bytesRecv]=NULL; printf("%S",recvbuf); if i run the code i get 5 in bytesRecv correctly.. but in recvbuf buffer three letters only available... like "hel" please help me l'm waiting for u... :^)

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Your string is not UNICODE, why do you want to print it as such? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • R rrthangavel

        Hai friends, i'm working with client server model socket programing using VC++. it has MFC SOCKET in client side and WIN32 SOCKET in server console application. i'm having proplem with receiving the strings in server side. i displayed part of code here Client Side Coding: UpdateData(1); CSocket client; client.Create (); CString sendstr; sendstr="Hello"; client.Connect ("127.0.0.1",2500); int len=sendstr.GetLength (); int sent= client.Send(LPCTSTR(sendstr),len); UpdateData(0); Server side coding: char recvbuf[32]="" ; int bytesRecv = recv( server, recvbuf, 32, 0 ); printf( "Bytes Recv: %d\n", bytesRecv ); recvbuf[bytesRecv]=NULL; printf("%S",recvbuf); if i run the code i get 5 in bytesRecv correctly.. but in recvbuf buffer three letters only available... like "hel" please help me l'm waiting for u... :^)

        M Offline
        M Offline
        Migounette
        wrote on last edited by
        #3

        Are you using TCP ? If yes, put the flag TCP_NODELAY. It's a classic error issue, in fact many people are confused by TCP. It's a simple example but with the TCP_NODELAY flag you should be able to receive your 5 bytes at once. [^]

        1 Reply Last reply
        0
        • R rrthangavel

          Hai friends, i'm working with client server model socket programing using VC++. it has MFC SOCKET in client side and WIN32 SOCKET in server console application. i'm having proplem with receiving the strings in server side. i displayed part of code here Client Side Coding: UpdateData(1); CSocket client; client.Create (); CString sendstr; sendstr="Hello"; client.Connect ("127.0.0.1",2500); int len=sendstr.GetLength (); int sent= client.Send(LPCTSTR(sendstr),len); UpdateData(0); Server side coding: char recvbuf[32]="" ; int bytesRecv = recv( server, recvbuf, 32, 0 ); printf( "Bytes Recv: %d\n", bytesRecv ); recvbuf[bytesRecv]=NULL; printf("%S",recvbuf); if i run the code i get 5 in bytesRecv correctly.. but in recvbuf buffer three letters only available... like "hel" please help me l'm waiting for u... :^)

          A Offline
          A Offline
          Ajay Vijayvargiya
          wrote on last edited by
          #4

          Your client side project is UNICODE. Either select MBCS in project settings, or **CStringA** sendstr; sendstr="Hello"; client.Connect ("127.0.0.1",2500); int len=sendstr.GetLength (); int sent= client.Send( **LPCSTR**(sendstr),len); CString is macro, which translates to CStringA or CStringW. You can assign either Unicode or ANSI string, CStringW/CStringA will take care of that.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups