[xSocket-develop] Sometimes weird result in onData() - Threading issue?
Status: Inactive
Brought to you by:
grro
|
From: Thomas S. <ts...@ib...> - 2008-02-18 15:10:28
|
Hello,
I have the following onData() handler:
EODProtocolContent ch = (EODProtocolContent) con.getAttachment();
if (ch == null) {
ch = new EODProtocolContent(con.getRemoteAddress().getHostName());
}
int commandIndex = ch.getCommandIndex();
switch (commandIndex) {
case MCIProtocol.MCI_COM_MACADDRESS : // MAC address
ch.getEodDataPacket().setMacAddress(con.readStringByDelimiter(newLine));
// Authentication
if
(!ch.getEodDataPacket().authenticate(ch.getEodDataPacket().getMacAddress()))
{
ch.setReturnCode(MCIProtocol.MCI_RC_AUTHENTICATION_FAILED);
}
break;
case MCIProtocol.MCI_COM_CHECKSUM: // Checksum
...
}
...
if (ch.getReturnCode() < 0) {
con.setAttachment(null);
} else {
ch.setCommandIndex(commandIndex + 1);
con.setAttachment(ch);
}
if ((ch.getReturnCode() < 0) || (ch.getCommandIndex() ==
MCIProtocol.MCI_COM_ENDOFPACKET)) {
// Write the return code if there was an error message or everything
went fine
con.write(String.valueOf(ch.getReturnCode()) + newLine);
con.flush();
}
Basically, EODProtocolContent is a wrapper around another object called
EODDataPacket and a few scalar data members. EODDataPacket has a few
setters and getters and also methods which accesses a database.
ch.getEodDataPacket() is simply a getter for returning the instance of a
EODDataPacket in EODProtocolContent.
With a self-written load testing tool, which basically send e.g. a MAC
address (the first line in a self-defined protocol), it sometimes happen
that ch.getEodDataPacket().authenticate(...) fails with an error
message, because there is rubbish in the macAddress data member. E.g.:
x?????q?oq?7???B?[A?L"6 ????Ev??9?#N?????k?j?/????_}?????_}????????}???~????~??????~???????????o???|??????~?????????_???????#?4???l?/v|??g?5?????????????????????%??????????_????????????}?????w?|?????}???>?????_??????^_???u>??_TO???G???_??3:???????_lt???[????_l4?3???}?~b?F?????J>oz{??X?Ry+????o{F_?4?[?sxV?s?????????V???~z?7??[???hx??>g??=?????Y?O%?5=????{S?c3??6#????????_??:???-o[????aZb?T?
?0?U??:?u-#?5/?*8M?}???}-?4??????=?~?~??0??o1???V?5?'??}??z?{???)?zL??{'?????}M3V??}?K-F,??6?5??)??O?:???ok,?
7\??f?Oz?E??l???1????]3TKC????YE??iB?j?i???z??#&?jg?a???2???m?b?f??????j?}Bw??k?
??Zo?ZE??U??f\?
V?j|@?N?U?????W?V?g????[???}?zV?U????K?4c?N?-3?:?}?t?%?s?k???Zs?u?Mk]f,q?{???<?7????t?}??G??ps?Q??1???k-5
For instance, if open 100 connections and send every 50 ms data to the
server, the above sometimes happen and sometimes not.
Any ideas what can cause this? Some kind of multi-threading issues?
@Gregor: I'm sorry for my last reply directly to your private email
address. This happens when I simply click reply in a posting in the list.
Thanks,
Thomas
|