Sign in to follow this  
Djvilppu

C# Socket problems

Recommended Posts

[font="Arial"][size="2"]Hello,[/size][/font]

[font="Arial"][size="2"]I am making some little scale multiplayer game with C# (.NET 4..0) and sockets... And now I need some socket expert help.[/size][/font]

[font="Arial"][size="2"]All have gone before well. M[/size][/font][font="Arial"][size="2"]y "good" clients takes [/size][/font][font="Arial"][size="2"]bandwich (both uplload and download) [/size][/font][font="Arial"][size="2"]about 2kbs / sec.[/size][/font]

[font="Arial"][size="2"]Now I got few tester with bad connection. [/size][/font]
[font="Arial"][size="2"]Bad connection causes server uppload bandwich jump up to 1000kbs per/sec a[/size][/font][font="Arial"][size="2"]nd it [b]totally incapacicate server.[/b][/size][/font]

[font="Arial"][size="2"]Some point of interests:[/size][/font]
[font="Arial"][size="2"]* Using TCP/IP[/size][/font]

[font="Arial"][size="2"]* I launch one thread per client (Will be good on my game, I need about 10 connections max)[/size][/font]

[font="Arial"][size="2"]* When is set TcpClient property NoDelay = true... This will make things even worse! (And it is strange)[/size][/font]
[size="2"][font="Arial"]- [/font][font="Arial"]NoDelay = false. (Bad connections cause about 400kbs/sec spike to client!)[/font][/size]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][size="2"][font="Arial"]- [/font][font="Arial"]NoDelay = true. (Bad connections cause about 1000kbs/sec spike to client!)[/font][/size][/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"] [/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][size="2"]* I give threads sleep when they got time with method "System.Threading.Thread.Sleep(100);" (Is this right way to do it?)[/size][/font][/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"] [/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][size="2"]* Using binaryformatter and networkstream.[/size][/font][/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"] [/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][size="2"]* Using .NET 4.0.[/size][/font][/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"] [/font][/font]
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][size="2"]I put with my client codes in zip:[/size][/font][/font][/font]
[font="Arial"][size="2"]Client.cs[/size][/font]
[font="Arial"][size="2"]DatanHandler.cs[/size][/font]

[font="Arial"][size="2"]and serverside:[/size][/font]
[font="Arial"][size="2"]Server.cs[/size][/font]
[font="Arial"][size="2"]ClientHandler.cs[/size][/font]

[font="arial"][size="2"]Attention!:[/size][/font]
[font="arial"][size="2"]I have simplified code for GameDev-post. But all important should be there.[/size][/font]

[font="arial"][size="2"]So my question is:[/size][/font]
[font="arial"][size="2"]What am I doing wrong?[/size][/font]
[font="arial"][size="2"]What is right way to fix it?[/size][/font]
[font="arial"][size="2"]Do you see some other major problems on my code?
[/size][/font]
[font="arial"][size="2"]Ps. I will send more info if needed.[/size][/font]

Share this post


Link to post
Share on other sites
[quote name='DJV' timestamp='1313731126' post='4851057']
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][size="2"]I put with my client codes in zip:[/size][/font][/font][/font]
[/quote]

It's unlikely anybody will download your code and unzip it just to read it and maybe find a problem.

What have you tried on your own? If you capture the traffic with WireShark, what data is being sent? When you see the large bandwidth usage, which kinds of data packets are you seeing in the client and server side? Are you logging a message for each packet sent and received? Have you stopped the program while it's being "bad" and single-stepped through it in the debugger to see what it's doing?

Share this post


Link to post
Share on other sites
[quote name='hplus0603' timestamp='1313790744' post='4851401']
[quote name='DJV' timestamp='1313731126' post='4851057']
[font="Arial"][font="arial, verdana, tahoma, sans-serif"][font="Arial"][size="2"]I put with my client codes in zip:[/size][/font][/font][/font]
[/quote]

It's unlikely anybody will download your code and unzip it just to read it and maybe find a problem.

What have you tried on your own? If you capture the traffic with WireShark, what data is being sent? When you see the large bandwidth usage, which kinds of data packets are you seeing in the client and server side? Are you logging a message for each packet sent and received? Have you stopped the program while it's being "bad" and single-stepped through it in the debugger to see what it's doing?
[/quote]

* No I have not captured traffic. (This first time I use WireShard... and it seems to be tool what I just need).

* Yes I have tried debug when things goes bad but got nothing from it yet.

[quote]Are you logging a message for each packet sent and received?[/quote]
I have not this kind technology on my game.. But I add it now.

I post more info if needed.. But I think I am going well with WireSharks.
Thanks.

Share this post


Link to post
Share on other sites
Found problems with [color="#1C2837"][size="2"]WireShark. [/size][/color]
[size="2"] [/size]
[color="#1C2837"][size="2"]My "Command queue" got bug. Bug fixed.[/size][/color]
[color="#1C2837"][size="2"]Now all clients takes ~ 5 Kbs/Sec.[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]This thread can be closed.[/size][/color]
[color="#1C2837"][size="2"] Thanks.[/size][/color]
[size="2"] [/size]
[size="2"] [/size]
[size="2"] [/size]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this