NIO Noise??

When running my game on local host with my server opening a port, then the client looking for 127.0.0.1 and port number, all is well.

When I adjust the client to use my servers true IP addres 68.#.#.# and the same port, I get some garbage, the same garbage at the same exact point in the data feed. Losing my mind debuggin this. Did I miss something on the server?

Any thoughts?

Be more precise about the nature of the unexpected data and where it is interjected in the expected data.

You should also, as a matter of course, use http://ethereal.com to packet-sniff and see where the data is coming from / going to and what other traffic is flying around - although in this case it’ll amost certainly tell you nothing relevant.

I made some adjustments and got rid of the blip, but still cant chat with not using local to local connection. One thing I am doing, which may be wrong, is chat comes in and is sent to a method which imediately sends a bytebuffer to all users.

All the while a loop is running that is sending bytebuffers to all players of all movements, over and over. I guess is is possible that I am simultaneouly writing to a channel from 2 different methods? or is this how is is done. I admint I am not very knowledgeable in NIO.

Thats probably it. Do not write to a stream from more than 2 threads. You can sometimes get the same “problem” with System.out if you are printing from more than one thread. You can get a line printed inside another line, if you know what I mean.

Anyway, you absolutely have to synchronize your code.

Great! So it is either allow th loop to contunie and put everytihgn someone needs inthe packet taht gets sent on that iteration or ‘synchriozed’ the methods? I will give it a whirl.

EDIT: prelim test show the “synchronized” may have helped. As soon as I replace my heat sink, I will get someting online to test.

dag nabbit… my changes worked on my dev box, but not my “production” box. phooey… back to the drawing board.

It’s possible that just making the method synchronized is not enough. What you need to do is learn all there is to know about threading and synchronization, or you’ll be walking a mindfield forever. That said, I don’t know of any links :frowning: I know there are books on the subject. Buying one would be a great investment.

May have to do the bookstore thing. I was able to get a number of different games to work using pre-nio socket networking… I not only need to learn more about nio, but find where I am obviously making a boo-boo in code. :slight_smile:

ok, after some pain in the butt testing, I have found that my communication has some holes. When I run my server on port 127.0.0.1 and the client runs locally connected to 127.0.0.1 all is well.

When I run my server on port #.#.#.# (not local) and run the client locally, but pointing to said new port, all communication takes paces except for chat communications.
Here is the odd part. I build a bytebuffer with an int id marker and the charset.coded string. The server receives the chat and, thru some debugging I can see this, then it is placed in the outgoing queue for that client, but the client never receives it. My receiving loop never even shows me the int marker id, thus I beleive it neve even makes it. I send other text in other buffers, so my router shouldnt be the issue.
I guess I should fire up the server and have some people outside of my office try it to see if they can chat.

With NIO you could do everything from one thread, that is what I am doing. I also have a LinkedList of outgoing packets which at any time in the game frame can be added to, my send method (called once per frame) simply grabs the first few on the list to send each frame.

Don’t forget that with SocketBuffer, it’s just a stream of bytes. There’s no packet start and packet end markers like there were with Object[Output/Input]Stream. So you need to first send the number of bytes, then keep waiting on the other end until all the bytes have arrived, then the game packet can be processed. ByteBuffer.compact() is useful for when you only have half a packet in the buffer, but need to get more space so the rest can be recieved (hopefully though, your game packet is sent in one transmittion and half/packets are fairly rare – they would certainly be more common with laggy connections over the internet).

I found the Java NIO book useful, and I read it online though Safari.

Will.

As far as I can tell I am doing that. Just very weird that it only fails on the transmission of a chat message?

I have naroowed it down to my server. I have no problems goin through the office firewals, and in one instance thru 3 different ones and multiple routers. But when I connect to my home system, thru my Linksys wirelsess, I get no chat! It is time for a beer and a fine cigar!

[quote]I have naroowed it down to my server. I have no problems goin through the office firewals, and in one instance thru 3 different ones and multiple routers. But when I connect to my home system, thru my Linksys wirelsess, I get no chat! It is time for a beer and a fine cigar!
[/quote]
Is this TCP or UDP?

UDP generally has problems through NAT firewalls, which is almsot certainly what you have.

TCP. What is odd though is that it is only that specific packet. Int for length, int for type, then the data. All other bytebuffers go thru my router just fine. I have set debug code on the server that screen prints with a chat packet is sent and it never gets received. A movement packet can follow and is received correctly. doh!

ok, I ripped my network code (jsut server and client abstracts) out and put together a simple echo server with it and whipped up a gui chat client to talk to it. Fired it up on my home system and went far, far, away (work :slight_smile: ) and voila…no probs and very responsive. So…dramatic pause…it must be my code around handling the chat packets within my game. doh! Wil post more when I know more.

Well…still fails. :frowning:

Still think its my code, though, since one works and the other doesnt.

%**& &#$) ^&%$^# !!!