Jump to content
  • Advertisement

Project: Unsettled World

Stateless Frustrations Frustratingly Stated (Handling Improperly Disconnected UDP Clients?)

Septopus

887 views

So, after weeks of strange and seemingly intermittent/coincidental UDP server crashes(Receive Thread Halt/Un-catchable Exception) and the ensuing frustration that that causes when you aren't even trying to work on the server itself.  I sat down and spent a day trying to figure out the problem..  After an almost complete server rewrite from scratch with no real improvement in the problem.. I turned to random poking about on the internets..

Hmmm...  It seems like the problem only happens when I'm restarting the client..

Here's a post!!

https://stackoverflow.com/questions/38191968/c-sharp-udp-an-existing-connection-was-forcibly-closed-by-the-remote-host

And Here!

https://social.msdn.microsoft.com/Forums/en-US/6b7aa353-259b-4637-b0ae-d4e550c13e38/c-udp-socket-exception-on-bad-disconnect?forum=netfxnetcom

Yup, that's the problem for sure.

It appears that even though UDP isn't supposed to care about the other ends state, apparently this isn't true if the state is Port Unreachable.  When the server attempts to receive data (BeginReceiveFrom/BeginReceive/EndRecieveFrom/EndReceive/etc..) from an async connection and the client has (Crashed/Quit/Etc.) an ICMP port unavailable packet is generated and this causes the UDP socket to generate an exception that (even if you try/catch the hell out of it) causes the async receive thread to halt(I assume, this is the effect anyhow).

The best solution I've found, as stated in the link(s) above is to change the underlying IOControl behavior(Prevent the Exception from being thrown).

//This value tells the underlying IO system to IGNORE the ICMP error.
public const int SIO_UDP_CONNRESET = -1744830452;
private Socket _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

_socket.IOControl((IOControlCode)SIO_UDP_CONNRESET, new byte[] { 0, 0, 0, 0 }, null);
_socket.Bind(new IPEndPoint(IPAddress.Any, port));

The first line is the value that needs to be set, and the second to last line is how you can set it.  And these are the live bits of code that are WORKING without error in my server, Finally! 

So, there, I've posted it again because it seems way more obscure than it should be.

Enjoy. ;)




0 Comments


Recommended Comments

I guess it's worth adding that my server handles client timeouts as part of it's core behavior, simple timeouts for inactivity/etc, and doesn't use any of the UDP connections "state" info for the decision process..  So the only potential negative side-effect of not properly trapping this exception and removing the user's EndPoint immediately is that a few extra packet sends get attempted to the dead client before the player's EndPoint gets forgotten anyhow.  So far, it's not an issue, hopefully it stays that way. ;)

Share this comment


Link to comment

Additionally I may be experimenting with rewriting my server so that it doesn't use the VERY same thread for every single receive operation, doing this probably would have prevented my server from having issues in the first place as only the thread serving the dead client would be halting.  And the extra exception was already going unnoticed anyways. lol... 

Share this comment


Link to comment

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
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By Florian Gionnane
      Hi everybody !
      We are an indie startup called Darkstar Games !
      We are just creating our first game called Greater powers, a novel type medieval fantasy TCG MMORPG with which we use unity. 
      We develop our games for Android, PC, iOS, and we have a software kit developer contract with Microsoft to adapt them to VR Microsoft HoloLens and VR Magic Leap in the future.
      We are developing our own alpha for the Kickstarter campaign at the moment !
      So we are actively searching for motivated programmers willing to take place in our project to build the engine we are creating of our own right now ! The game is coded in C# and any unity experience is greatly appreciated! 
      We collaborate to the startup worldwide remotely !
      Programmers collaborating to the project such as building the alpha become shareholders and are hired in the start-up launch !
      Here are some links about the project:
      https://www.artstation.com/floriangionnane
      https://www.facebook.com/DarkstarGamesCorp
      https://connect.unity.com/p/games-greater-powers
      If anyone interested, please send your resume to flosambora123@gmail.com
      Have a nice day !
       


    • By Glasshalfpool
      Hi there
      I'm working on a simple racing game at the moment that I like to pitch as Thumper vs. Burnout vs. Journey.
      In a nutshell it's a single player experience where the player races across a city in the dead of night with a time limit of one hour. The main mechanic being that driving well earns the ability to go faster, making things more challenging and opening up shortcuts and alternative routes, while mistakes (colliding with walls for example) make the player loses their highest speed and have to re-earn it.
      I have a grand vision for an a pounding, dynamic sound track with elements being added to the music as the player goes faster and I'm looking for someone to collaborate with on the audio effects.
      Here is a video of the early direction and feel of the project (it's moved on since, but this still gives a sense of the style):  
       
      Contact me if you're interested in the opportunity to work on an interesting unique soundscape with me.
      Kind regards,
      Jamie
    • By INTwindwolf
      COMPANY AND THE PROJECT
      We are an indie game studio consisted of professional and skilled artists who are dedicated indie enthusiasts. Our current project is INT, developed on Unity Engine 5 for platforms Windows, Linux, and Mac. We are recruiting a few more members on the team to finalize our playable demo.

      INT is a 3D Sci-fi RPG with a strong emphasis on story, role playing, and innovative RPG features such as randomized companions. The focus is on the journey through a war-torn world with fast-paced combat against hordes of enemies. The player must accomplish quests like a traditional RPG, complete objectives, and meet lively crew members who will aid in the player's survival. Throughout the game you can side and complete missions through criminal cartels, and the two major combatants, the UCE and ACP, of the Interstellar Civil War.
      Please note that all of our current positions are remote work. You will not be required to travel.
      For more information about us, follow the links listed below.
      INT Official website
      IndieDB page
      Also follow social media platforms for the latest news regarding our projects.
      Facebook
      Twitter
       
      UNITY ENGINE PROGRAMMER
      We are looking for Unity Programmers. You will be working with our Coding team Lead to implement systems and mechanics using C# language.
      Your duties will include:
      Attendance of regular team meetings. Timely completion of implementation of assets. Direct contact with Project Lead and other Department Leads for the implementation process. Utilization of version control suites. Utilization of our project management boards (Trello) and communication channels to obtain up-to-date assets.  
      REQUIREMENTS
      To be successful in this position, following requirements apply:
      Clear communication and self starter - pushes to meet deadlines and contribute to the project. Ability to complete tasks with limited input/direction from management. Comfortable with working with people remotely and via Trello management system. Good internet connection with ability to update assets/builds quickly, with large dependencies. At least 15 hours of availability each week. Proficient experience using the Unity Game Engine. Proficient experience in implementing assets into the Unity Game Engine. OTHER OPEN POSITIONS
      3D Environment Modeller
      Website Manager
      3D Character Modeller
      REVENUE - SHARE
      The project is marching increasingly closer to be ready for our crowd-funding campaign. Being an Indie team we do not have the creative restrictions often imposed by publishers or other third parties. We are extremely conscientious of our work and continuously uphold a high level of quality throughout our project.
      We are unable to offer wages or per-item payments at this time. However revenue-sharing from crowd-funding is offered to team members who contribute 15-20 hours per week to company projects, as well as maintain constant communication and adhere to deadlines. Your understanding is dearly appreciated
      TO APPLY
      Please send your Cover Letter, CV, Portfolio (if applicable), and other relevant documents/information to this email: JohnHR@int-game.net
      Thank you for your time! Please feel free to contact me via the email provided should you have any questions. We look forward to hearing from you!
      John Shen
      HR Lead
      Starboard Games LLC
    • By aa d
      hello guys,
      i'm new in unity and i wanna make a ricing game , but i don't know how to start. The script of  racing games in youtube is very bad how i wanna a better script but i don't know how and where to start ,
      is any one here can help me ?
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!