Weird phenomena, I probably have some weird bug in my code

41 views
Skip to first unread message

goodnews...@gmail.com

unread,
May 6, 2018, 1:45:55 AM5/6/18
to Netty discussions
Hello,

I've been making Netty server based games for over a year.

Today I have a weird bug.

No matter what I send to:
ChannelHandlerContext storectx;

storectx.write(bb);
storectx.flush();

My c# client receives
12300 <some more garble>

If I send a single character,
My c# client recieves
1

If I send two characters
My c# client recieves
12

If I send three characters and this can be anything like "AAA" "ABC"
My c# client receives
123

At first, the c# client and Java Netty Server do fine, but at a certain line, it always does this.

I'm curious what I should investigate?
Any general or specific tips would be helpful.

goodnews...@gmail.com

unread,
May 6, 2018, 12:12:35 PM5/6/18
to Netty discussions
Is there some way to read the data that is wrote into:

ChannelHandlerContext.write(ByteBuffer);

Maybe something got put there that I am not aware of.

goodnews...@gmail.com

unread,
May 6, 2018, 1:01:33 PM5/6/18
to Netty discussions
Ok, I am debugging this further.

It seems like my client sends a data packet to the server.
The server reads it properly.

But when my server sends data back to the client, the client only reads its own packet that it sent to the server previously.
It is only as many bytes as it sent.

So I am sending from client:
123000

When the server sends any packet back to the client, say "A"
The client reads in "1"instead of "A"

If I send"ABCD"
The client reads in "1230"

Is there something I should know about ChannelHandlerContext?
Is it possible for ChannelHandlerContext.write(bytebuffer) to be corrupted by input somehow?
I do not write to the ChannelHandlerContext anywhere else.

The whole system seems like it runs fine except for when I send in one particular place.
If I send the same packet twice, it sends the echo packet just once then resumes sending normally.
So I could just give up, cry anomoly, and send the packet twice and my program would work.

But I want to track this down while I can so it doesn't pop up elsewhere.

What could be causing an echo? An echo that only happens when I .write different data out and only to the length of the data?

goodnews...@gmail.com

unread,
May 6, 2018, 1:20:40 PM5/6/18
to Netty discussions
Okay yah it was some weird bug in my code and I'll tell you what it is.

I had a global variable data that I read/wrote with.

So something with multithreaded corruption was going on I believe.

Anyway kids, don't use the same global variable for writing/reading in a multithreaded environment... duh.

I'm happy. Thank you guys for your help in the past and well wishing and prayers now.

goodnews...@gmail.com

unread,
Mar 7, 2019, 2:56:27 AM3/7/19
to Netty discussions
What I did was: I have all my locked variables all I check for new messages.

Then my main code reads in the new messages and processes them in another thread, accessing em behind A lock. Boom, easy mode.
Reply all
Reply to author
Forward
0 new messages