none
NetworkStream.BeginRead() Error (System.Net.Sockets.SocketException) RRS feed

  • Question

  • I have an application that can be a master server or a spawner (one EXE file), depending on the arguments provided when running it with the Command Prompt. The spawner code is ported over from a Unity 3D application. I have tried these:

    Run the master server application (the EXE file), then run the Unity 3D application. The Unity 3D application can connect to the master server application.

    Run the master server application (the EXE file), then run the spawner application (the same EXE file). The master server application is forcefully closed with this error message:

    "Unhandled Exception: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.BeginReceive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state) at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) at ServerApplicaton.Spawner.Start() in C:\Users\User\Test\Spawner.cs:line 29"

    These are the code in the CS files:

    1. Program.cs:

    https://dotnetfiddle.net/rEEs77

    2. SpawnerNetwork.cs:

    https://dotnetfiddle.net/kaDf5A

    3. MasterServerNetwork.cs:

    https://dotnetfiddle.net/GA2o0T

    4. Spawner.cs:

    https://dotnetfiddle.net/JxqakO

    I run the application (the EXE file) locally with these commands:

    To run the master server application:
    ServerApplicaton.exe /masterServerIP:127.0.0.1 /masterServerPort:5554 /spawnerIP:null /spawnerPort:null

    To run the spawner application:
    ServerApplicaton.exe /masterServerIP:127.0.0.1 /masterServerPort:5554 /spawnerIP:127.0.0.1 /spawnerPort:5554

    Did I miss anything on the code?
    Tuesday, July 10, 2018 2:52 PM

All replies

  • Hi johntravolta123456789,

    Thank you for posting here.

    According to your description, I think maybe the C# spawner code which is ported over from a Unity 3D application are wrong. Please post a new thread in Unity forum.

    https://forum.unity.com/

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, July 13, 2018 2:59 AM