specifically is this:
mina -side filter if it is using a TextLine, but added there is no problem , mina server and c + + client can perform normal communication (TextLine easier here , as long as the message will be sent followed by a string \ n no problem ) .
Similarly, if it is a server + mina mina client , server, and client filter use ObjectSerialization ... when the server and client Clients to byte [] for the unit to communicate with no problem.
strange , if it is mina- server + cpp client , server, and client filter are used ObjectSerialization ...
time , cpp client to the server using bsd socket mina tcp link sent to char [] data when , mina server the messageReceived end handler method does not respond the ( client can connect to the server , but the server side does not receive char [] data ) .
difficult for a long time and have done a lot of testing , such as:
will filter all removed ( in fact, is a ObjectSerialization ... filter), the situation has changed ,
The messageReceivde server handler method can respond , but print out received message object is a HeapBuffer object.
Here is my question :
1.c + + client to bsd send method to send over the char [] data how to not trigger messageReceived way ?
2. HeapBuffer decoder in the end this should be how to write ( the HeapBuffer converted to byte [])?
3. single serving from 2000 to 3000 people SLG type of game (ios games Clash of Clans, pc side of the page tour gold country ) , the client and server communications should use tcp or udp to do ?
asked so much about it , I hope passing experienced great God gets advice maze , very grateful !
------ Solution ---------------------------------------- ----
matter what, the last pass are byte , Java which is equivalent to a byte array , it is recommended to write their own codecs
------ Solution ------ --------------------------------------
c + + a char is one byte , Java is actually a two -byte , perhaps for this error now
------ Solution --------------------------- -----------------
I was also recently used a java beginners point mina read your reply I also learned something first may indeed be a problem , as you say should be the object serialization ObjectSerialization I understand java object serialization is allow objects can be saved or sent through the network a continuous buffer c + + in the original object is not even a buffer , even if the object is the object of two languages is certainly not do conversion so I figured this filter only client is written in java job
The second problem message should be a IoBuffer it, this should be c + + on the concept of a buffer almost see what the client made the original so few data types will I was kind of plastic surgery and other methods used getInt getShort but encountered a problem is big-endian little endian problem I use the first string into InputStream then read Lane converted to byte strings
------ For reference only ----------------------------- ----------
I looked at ObjectSerialization .. Decoder implementation , found a little clue , I suspect that such a situation:
java byte array sent when the underlying data length of the byte array is sending a message to get on the first four bytes inside,
but if it is using c + + to send a char [] data, because the underlying implementation is different, so the head of the transmission data length of the data is not named in this 4 -byte so ObjectSerialization .. Decoder decoding fails , messageRecv method is not triggered.
previous paragraph ObjectSerialization .. Decoder code :
@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
if (!in.prefixedDataAvailable(4, maxObjectSize)) {
return false;
}
out.write(in.getObject(classLoader));
return true;
}
------ For reference only ----------------------------------- ----
prefixedDataAvailable relevant information :
http://scholers.iteye.com/blog/728377
circumstances yet to be verified , Office Equipment not in place , temporarily can not be tested , egg pain
------ For reference only -------------- -------------------------
premise that communication protocols before 4 bytes length of data sent
---- - For reference only ---------------------------------------
You misunderstood , java inside pass is byte [], is a byte units , c + + inside the char is one byte , this should not be the key issue
------ For reference only ---------------------------------------
C + + you use the char data transfer , Java Lane is byte received it
------ For reference only --------------------- ------------------
not receiving hand-written code, with a framework , which specifically what way it received I'm not sure
------ For reference only -------------------------------------- -
If it just pure string , java server and c + + client communication as long as the note with the \ n at the end on the line ( for filters TextLine), big-endian turn the small end only for sending a single plastic , short , do not do for the flow of processing . Is also thought to be misled before all data transfers to do a deal with the size of side transformations , was tossing a while
In the near future you can do the test , and the time If, as I judge in that case, will the crux Tieshanglai
------ For reference only --------- ------------------------------
find the reason , java and java communication when objects are sent out both ends are encoded as a sequence of bytes , and I from c + + client sends data to the java side , just out from the object into a sequence of bytes , rather than coding sequence of bytes out . The crux of the problem can be attributed to c + + client does not have readily available, similar ObjectSerializationCodecFactory codec factory class. . Hey ~
------ For reference only ------------------------------------ ---
find the reason , java and java communication when objects are sent out both ends are encoded as a sequence of bytes , and I from c + + to the java side sends the data out only by the object into a sequence of bytes , rather than out of the coding sequence of bytes. The crux of the problem can be attributed to c + + client does not have readily available, similar ObjectSerializationCodecFactory codec factory class. . Hey ~
------ For reference only ------------------------------------ ---
byte sequence ?
------ For reference only -------------------------------------- -
is not big-endian and little-endian problem ?
没有评论:
发表评论