Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by leethfs · Nov 13, 2020 at 05:34 AM · bugthreadingsocket

unity socket bug or Threadpool bug ? please help,,

 using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using System;
  using System.Text;
  using System.Net;
  using System.Net.Sockets;
  using System.Diagnostics;
   
   class Client
   {
       private Socket socket;
       private byte[] buffer = new byte[1024];
       private StringBuilder sb = new StringBuilder();
       public Client(Socket socket)
       {
           this.socket = socket;
           this.socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new System.AsyncCallback(Receive), this);
       }
   
   
       private void Receive(IAsyncResult result)
       {
           if (socket.Connected)
           {
               int size = 0;
               try
               {
                   this.socket.EndReceive(result);
               }
               catch (Exception e)
               {
                   UnityEngine.Debug.Log(e.Message);
                   return;
               }
   
               this.socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, Receive, this);
           }
       }
   }
   
   class ServerSocket : Socket
   {
       public ServerSocket() : base(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
       {
           base.Bind(new IPEndPoint(IPAddress.Any, 7902));
           base.Listen(0);
   
           BeginAccept(Accept, this);
       }
   
       private void Accept(IAsyncResult result)
       {
           UnityEngine.Debug.Log("ServerSocket threadID:" + System.Threading.Thread.CurrentThread.ManagedThreadId);
           var client = new Client(EndAccept(result));
           BeginAccept(Accept, this);
       }
   }
   
   public class Test : MonoBehaviour
   {
       void Start()
       {
           new ServerSocket();
       }
   
       public static void OpenHandler(Network.Session.NetSession session)
       {
       }
   
       // Update is called once per frame
       void Update()
       {
       }
   }
 




hi

We have question about Unity Socket and ThreadPool.

Server code was written in the Unity project and processed by Asynchronous.

AsyncCode, such as "BeginAccept", "BeginRecive", is written, and we wrote a code that only requires the connection with a bot simply.

But we run servers within Unity if it has more than 1,000 connection counts, WookerThread by increases momentarily, and the connection fails.

If we turn the server in the C# project with the same code as above, there is no problem. But if we run the server in Unity, that kind of problem will happen.

If we comment "BeginReceive" code in the code, it connects normally.

We think it's a Threadpool issue. The "ThreadPool.SetMaxThreads" function was called to control the number of threads.

Thread does not increase when the function was called, but if more than 1000 connections, the problem occurred.

There's nothing wrong with being under 1,000.

Then we accept, about 4 types of Thread ids are process, and if more than 1,000 connections ( around 1,030) had connected, the Thread would rapidly increase and can't connect.

We don't know if this is a Unity-related Bug or a user problem.

We are looking forward to you and hope you can help with this problem.

I added the code.

and

Calling Threading.ThreadPool.GetMaxThreads(out int workerThreads, out int

completionPortThreads) in Unity Project

C# Project : workerThreads:1023, completionPortThreads :1000

Unity Project : workerThreads:800, completionPortThreads :200

calling ThreadPool.SetMaxThreads(1023, 1000) in unity project.

But the phenomenon is the same...

thank.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

236 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue with mouse input when locking the cursor 2 Answers

Failed to Load window layout , what to do ? 3 Answers

Universal render pipeline + pixel perfect + cinemachine + Unity 2020.1.14f 0 Answers

Nested class Lists inspector overlapping bug 1 Answer

My game is slower after changing my computer 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges