Results 1 to 3 of 3

Thread: Why the Chinese character pass between application write with C++ and C# has question

  1. #1
    lotusqin is offline Registered User
    Join Date
    May 2005
    Posts
    2

    Question Why the Chinese character pass between application write with C++ and C# has question

    When I pass Chinese character as parameter from ICE client application write with C# to ICE server application ,I find the ICE server application recieved the parameter not crrect (Client send 2 characters but Server recieved 3 characters and not inclue the 2 characters witch the client send,they are all different.)
    I write the "Hello.ice" file ,changed the "nonmutating void sayHello();" to "nonmutating void sayHello(string ps);" ,the "ps" is the parm I pass Chinese character .
    I rework the "hello world" demo server project write with C++ ,I change the function "sayHello" of classs HelloI as next
    HelloI::sayHello(const string & ps,const Ice::Current&) const
    {
    //cout << "Hello World!" << endl;
    cout << ps << endl;
    }
    Then I rework the "hello world" demo client project write with C# .I change the function "run" of class client on the line followed "if(line.Equals("t"))" ,you can see the code with notes "//two Chinese characters " :
    private static int run(string[] args, Ice.Communicator communicator)
    {
    Ice.Properties properties = communicator.getProperties();
    string proxyProperty = "Hello.Proxy";
    string proxy = properties.getProperty(proxyProperty);
    if(proxy.Length == 0)
    {
    Console.Error.WriteLine("property `" + proxyProperty + "' not set");
    return 1;
    }

    Ice.ObjectPrx basePrx = communicator.stringToProxy(proxy);
    HelloPrx twoway = HelloPrxHelper.checkedCast(basePrx.ice_twoway().ic e_timeout(-1).ice_secure(false));
    if(twoway == null)
    {
    Console.Error.WriteLine("invalid proxy");
    return 1;
    }
    HelloPrx oneway = HelloPrxHelper.uncheckedCast(twoway.ice_oneway());
    HelloPrx batchOneway = HelloPrxHelper.uncheckedCast(twoway.ice_batchOnewa y());
    HelloPrx datagram = HelloPrxHelper.uncheckedCast(twoway.ice_datagram() );
    HelloPrx batchDatagram = HelloPrxHelper.uncheckedCast(twoway.ice_batchDatag ram());

    int timeout = -1;

    menu();

    string line = null;
    string ss;
    do
    {
    try
    {
    Console.Out.Write("==> ");
    Console.Out.Flush();
    line = Console.In.ReadLine();
    if(line == null)
    {
    break;
    }
    if(line.Equals("t"))
    {
    ss="好好";// two Chinese characters
    twoway.sayHello(ss);
    }
    else if(line.Equals("o"))
    {
    oneway.sayHello("阿");
    }
    else if(line.Equals("O"))
    {
    batchOneway.sayHello("阿");
    }
    else if(line.Equals("d"))
    {
    datagram.sayHello("阿");
    }
    else if(line.Equals("D"))
    {
    batchDatagram.sayHello("阿");
    }
    else if(line.Equals("f"))
    {
    communicator.flushBatchRequests();
    }
    else if(line.Equals("T"))
    {
    if(timeout == -1)
    {
    timeout = 2000;
    }
    else
    {
    timeout = -1;
    }

    twoway = HelloPrxHelper.uncheckedCast(twoway.ice_timeout(ti meout));
    oneway = HelloPrxHelper.uncheckedCast(oneway.ice_timeout(ti meout));
    batchOneway = HelloPrxHelper.uncheckedCast(batchOneway.ice_timeo ut(timeout));

    if(timeout == -1)
    {
    Console.WriteLine("timeout is now switched off");
    }
    else
    {
    Console.WriteLine("timeout is now set to 2000ms");
    }
    }
    else if(line.Equals("s"))
    {
    twoway.shutdown();
    }
    else if(line.Equals("x"))
    {
    // Nothing to do
    }
    else if(line.Equals("?"))
    {
    menu();
    }
    else
    {
    Console.WriteLine("unknown command `" + line + "'");
    menu();
    }
    }
    catch(System.Exception ex)
    {
    Console.Error.WriteLine(ex);
    }
    }
    while (!line.Equals("x"));

    return 0;
    }
    After I run the two application,they are show as the attach Files I send.
    Attached Files Attached Files
    Last edited by lotusqin; 05-23-2005 at 04:17 AM.

  2. #2
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    Your program works fine for me with the following code for the C++ server:

    Code:
    #include <IceUtil/Unicode.h>
    
    void
    HelloI::sayHello(const std::string& s, const Ice::Current&) const
    {
        wcout << IceUtil::stringToWstring(s) << endl;
    }
    In C++, you need to use the IceUtil::stringToWstring() and IceUtil::wstringToString() to convert from string to wstring and vice versa.

    Hope this helps!

    Benoit.

  3. #3
    lotusqin is offline Registered User
    Join Date
    May 2005
    Posts
    2
    Thank you very much for your answer! I take it, Unicode is the matter.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 10-09-2011, 01:12 AM
  2. application architecture question
    By mangrish in forum Help Center
    Replies: 6
    Last Post: 12-18-2008, 01:09 PM
  3. Replies: 2
    Last Post: 12-12-2005, 09:10 AM
  4. Replies: 2
    Last Post: 11-21-2003, 07:46 AM
  5. Replies: 4
    Last Post: 11-20-2003, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •