| |

VerySource

 Forgot password?
 Register
Search
View: 778|Reply: 6

The maximum number of concurrent connections on the socket server is limited

[Copy link]

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-6 05:30:01
| Show all posts |Read mode
Do server
The main code is as follows:
        public SocketServer (EndPoint endPoint)
        {
            socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Bind (endPoint);
        }

        public void Start ()
        {
            connectDone = new ManualResetEvent (false);
            connectThread = new Thread (new ThreadStart (ConnectService));
            connectThread.IsBackground = true;
            socket.Listen (1024);
            connectThread.Start ();
        }

        protected void ConnectService ()
        {
            while (true)
            {
                connectDone.Reset ();
                socket.BeginAccept (new AsyncCallback (ConnectInit), socket);
                connectDone.WaitOne ();
            }
        }

        protected void ConnectInit (IAsyncResult ar)
        {
            Socket clientSocket = ((Socket) ar.AsyncState) .EndAccept (ar);
            connectDone.Set ();
            if (OnConnect! = null)
            {
                 NetworkClient client = new NetworkClient (clientSocket);
                 OnConnect (client);
            }
        }
When the client has more than 3 users connected at the same time, all subsequent connections cannot be connected. Hope you guys help me see it.
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-6-1 18:15:01
| Show all posts
There is a problem when the client segment creates more than three consecutive connections. If you do not create a connection Sleep (1000), there is no problem. The time of Sleep cannot be too short, otherwise the connection cannot be established.
Reply

Use magic Report

0

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-6 14:45:01
| Show all posts
Asynchronous
Reply

Use magic Report

0

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-6-6 16:00:02
| Show all posts
Multithreading
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-6-10 02:15:01
| Show all posts
All are asynchronous processing methods, including client connection and sending information, reading information, etc. are asynchronous, I found that the connection has been established through the port viewer, but more than 3 connections are unable to communicate, mainly to establish a connection The amount of concurrency can not be too fierce, you must build one every 1 second
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-6-10 11:30:01
| Show all posts
After quickly establishing 20 connections, sometimes only 2 can be used, sometimes only 3 can be used. If a connection is established after one second or more, there is no such problem. Everyone help me to see, feel dizzy.
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-2 12:00:01
| Show all posts
Not so, my program listen(200), I tested 20 clients connected at the same time. Each is handled by a separate thread. But there is no situation when testing large amounts of data.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list