Home Help Center

from client input two base class type parameters(one in, one out, the in parameter va

taojhlwkltaojhlwkl Member tao jinhuOrganization: CSST GroupProject: Network AD machine, I don't know how to migrate to
Dear ZeroC staff teachers,

I referenced ChatDemo-1.4.0 example (push polling clients).
I want from client input two base class type parameters(one in, one out, the in parameter value is son class type ) sent to server, and the client will retake a son class parameter from server.
such as:
int sendmessagefromclienttoserverorclient(DWLmessage mindwlmessage,out DWLmessage moutdwlmessage) throws InvalidMessageException;
the server implemented by c++ can run correct.(ubuntu13.04 32 bit gcc version 4.7.3 )
the pushclient pullclient implemented by c++ can run correct.(ubuntu13.04 32 bit gcc version 4.7.3 )
But the pushclient implemented by java(android4.3) can not run correct. the pushclient can't get the out (DWLmessage moutdwlmessage) parameter (son class), only can get the base class object.
How I can parse the NDWL.Usergetfriendlistackmessage object (NDWL.DWLmessage's son class) from NDWL.DWLmessageHolder parameter( seem as c++ code NDWL::UsergetgrouplistackmessagePtr pUsergetgrouplistackmessagePtr =
NDWL::UsergetgrouplistackmessagePtr::dynamicCast(
mindwlmessageptr);).

android client's code at Later in the article.
thank you very much.

//.ice file
//name space NDWL
module NDWL
{
//user infomation
class Userbaseinfo
{
string userid;
string password;
string usernickname;
string usernotename;
int hascheckcodeflag;
string checkcode;
int usertype;

};
dictionary<string, Userbaseinfo >Userbaseinfomap;
class Groupinfo
{
int groupid;
string groupname;
Ice::ByteSeq groupnamebufferseq;
int groupnamebufferseqsize;
int grouptype;
int groupsharestorespacesize;
Userbaseinfomap muserbaseinfomap;
};
// message base class
class DWLmessage
{
string fromuserid;
string touserid;
string fromserverid;
string toserverid;
int messageid;
long timestamp;
int result;//
};
//chat message is DWLmessage's son class
class Userchatmessage extends DWLmessage
{
string content;//
Ice::ByteSeq contentbufferseq;//
int contentbufferseqsize;//

};
//client get friendlist from server request message
class Usergetfriendlistreqmessage extends DWLmessage
{

};
//server send friendlist to client ack message
class Usergetfriendlistackmessage extends DWLmessage
{

int friendsum;// friend sum
int offset;//offset
int thistimefriendamount;//
Userbaseinfomap muserbaseinfomap;//userid is key
};

// other messages son class(base class is DWLmessage) etc ...
//start pushclient session
interface PushClientCallback //push client callback
{

int callbacksendmessagefromservertoclient( DWLmessage mdwlmessage);// server call this function send message to clients
};
//server implement functions for pushclient call
interface DWLPushSession extends Glacier2::Session //
{

// pushclient call this function send a message(mindwlmessage) to server and retake a message(moutdwlmessage)
int sendmessagefromclienttoserverorclient(DWLmessage mindwlmessage,out DWLmessage moutdwlmessage) throws InvalidMessageException;

//pushclient set callback
int setpushclientcallback(PushClientCallback* cb);//

};
//end pushclient session
//start pullclient session
sequence<DWLmessage> DWLmessageSeq ;
interface DWLPullSession
{

// pullclient call this function send a message(mindwlmessage) to server and retake a message(moutdwlmessage)
int sendmessagefromclienttoserverorclient(DWLmessage mindwlmessage,out DWLmessage moutdwlmessage) throws InvalidMessageException;

//for pull client to call the function to get updates(is DWLmessageSeq) by polling.
int getmessagesfromclienttoserverorclient(out DWLmessageSeq moutdwlmessageseq) throws InvalidMessageException;

};
//exception
exception CannotCreateSessionException
{
string reason;
};

//for DWLPullSessionFactoryI
interface DWLPullSessionFactory
{
//Pull client to logon
DWLPullSession * create(string userid, string password) throws CannotCreateSessionException;
};
//end pullclient session

}
reference ChatDemo-1.4.0
server is implemeted by c++; (ubuntu13.04 32 bit gcc version 4.7.3 )
push client and pull client implemeted by c++ can run ok (ubuntu13.04 32 bit gcc version 4.7.3 )
but push client implemeted by java(android4.3) can't run correct
server c++ code:
::Ice::Int DWLPushSessionI::sendmessagefromclienttoserverorclient(
const ::NDWL::DWLmessagePtr& mindwlmessageptr,
::NDWL::DWLmessagePtr& moutdwlmessageptr, const ::Ice::Current& current)
{
for (;;)
{
//receive client's Usergetfriendlist request message
NDWL::UsergetfriendlistreqmessagePtr pUsergetfriendlistreqmessagePtr =
NDWL::UsergetfriendlistreqmessagePtr::dynamicCast(
mindwlmessageptr);
if (NULL != pUsergetfriendlistreqmessagePtr)
{

//send friendlist to client
IceUtil::Mutex::Lock sync(mmutex);
::NDWL::Userbaseinfomap muserbaseinfomap3;

::NDWL::GroupinfoPtr pGroupinfoPtr3 = new NDWL::Groupinfo(3,
"groupname3", groupnamebufferseq, 1000, 1, 20000,
muserbaseinfomap3);
::NDWL::Groupinfomap mgroupinfomap;
mgroupinfomap[pGroupinfoPtr3._ptr->groupid] = pGroupinfoPtr3;
//set moutdwlmessageptr value
moutdwlmessageptr = new ::NDWL::Usergetgrouplistackmessage(
"fromuserid", "touserid",
"fromserverid", "toserverid", 1, 8945678, 1, 5, 0, 2,
mgroupinfomap);

break;

}

}

}
pushclient or pullclient want to get friendlist run correct
c++ code:
::NDWL::DWLmessagePtr moutdwlmessageptr;
string muserid="111";
::NDWL::DWLmessagePtr mindwlmessageptr =new ::NDWL::Usergetfriendlistreqmessage(muserid,"", "fromserverid", "toserverid", 1,123456789, 1);
::Ice::Int sendresult =msessionprx->sendmessagefromclienttoserverorclient(mindwlmessageptr, moutdwlmessageptr);

for (;;)
{

NDWL::UsergetgrouplistackmessagePtr pUsergetgrouplistackmessagePtr =
NDWL::UsergetgrouplistackmessagePtr::dynamicCast(
moutdwlmessageptr);
if (NULL != pUsergetgrouplistackmessagePtr) //is true
{
::NDWL::Groupinfomap::iterator iter1 =
pUsergetgrouplistackmessagePtr._ptr->mgroupinfomap.begin();
::NDWL::Groupinfomap::iterator iend1 =
pUsergetgrouplistackmessagePtr._ptr->mgroupinfomap.end();
while (iter1 != iend1)
{
// can run to this location
NDWL::GroupinfoPtr pgroupinfoptr = iter1->second;
iter1++;
}

break;

}

}
//pushclient want to get friendlist
java(android) code:
private NDWL.DWLPushSessionPrx _session; //anlready connected to server
string username="555"; //android client's userid (self)
byte[] contentbufferseq=new byte[100];
NDWL.DWLmessage mindwlmessage=new NDWL.Userchatmessage(username,"111","fromserverid","toserverid",2354,567777,236,"messagecontent",contentbufferseq,contentbufferseq.length);
//send chat message to other client(userid is 111) can run correct.
sendmessagefromclienttoserverorclient (mindwlmessage);
NDWL.DWLmessageHolder moutdwlmessageholder2=new NDWL.DWLmessageHolder();
NDWL.DWLmessage mindwlmessage2 =new NDWL.Usergetfriendlistreqmessage(username,"", "fromserverid", "toserverid", 1,123456789, 1);
sendmessagefromclienttoserverorclientandgetackmessage(mindwlmessage2,moutdwlmessageholder2); //send to server success , but moutdwlmessageholder2.value is NDWL.DWLmessage object, not NDWL.Usergetfriendlistackmessage object.
//NDWL.Usergetfriendlistackmessage usergetfriendlistackmessage=(NDWL.Usergetfriendlistackmessage)(moutdwlmessageholder2.value); //android client breakdown
if( (moutdwlmessageholder2.value) instanceof NDWL.Usergetfriendlistackmessage)// is false
{
//can not run this location
NDWL.Usergetfriendlistackmessage usergetfriendlistackmessage=(NDWL.Usergetfriendlistackmessage)(moutdwlmessageholder2.value);

}
//How I can parse the NDWL.Usergetfriendlistackmessage object (NDWL.DWLmessage's son class) from NDWL.DWLmessageHolder parameter( seem as c++ code NDWL::UsergetgrouplistackmessagePtr pUsergetgrouplistackmessagePtr =
//NDWL::UsergetgrouplistackmessagePtr::dynamicCast(
// maindwlmessageptr);).

synchronized public void sendmessagefromclienttoserverorclientandgetackmessage(NDWL.DWLmessage mindwlmessage,NDWL.DWLmessageHolder moutdwlmessageholder)
{

try
{
int result= _session.sendmessagefromclienttoserverorclient(mindwlmessage,moutdwlmessageholder);

}
catch(NDWL.InvalidMessageException ex)
{

}

}
synchronized public void sendmessagefromclienttoserverorclient(NDWL.DWLmessage mindwlmessage)
{

NDWL.Callback_DWLPushSession_sendmessagefromclienttoserverorclient cb = new NDWL.Callback_DWLPushSession_sendmessagefromclienttoserverorclient()

{
...
};

_session.begin_sendmessagefromclienttoserverorclient(mindwlmessage, cb);

}

Comments

  • taojhlwkltaojhlwkl Member tao jinhuOrganization: CSST GroupProject: Network AD machine, I don't know how to migrate to
    sorry I have a mistake. thank you .

    sorry I have a mistake. thank you .
Sign In or Register to comment.