I have C# socket sever. Max clients count who able to connect with server about 800. If clients more then 800 new clients get socket error WSAECONNREFUSED 10061. How raizeup max clients count?
Socket write between socket.BeginXXX and socket.EndXXX. Target: framework 4.0. Protocols: IP4, TCP
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
The listener backlog queue is full. When the backlog queue is full Windows will start sending RSTs to further incoming connections, which become 'connection refused' at the client(s) concerned. You can raise the backlog queue length as per other answers here, but what it really means is that you aren't processing accepts fast enough. Take a good look at the code that does that, and grease the path. Make sure it doesn't do anything else, such as blocking I/O, disk I/O, other network operations. Once the connection is accepted it is off the backlog queue so other incoming connections can succeed.
When setting the serversocket to its listen state you can set the backlog. That is the maximum number of connections that can be waiting to be accepted.
Everything else is possibly a hardware issue - try running the program on a different machine.
Here is an example of a
Socket serversocket = ...
serversocket.Listen(1000);
Hi i find answer on my question. I create additional thread for accept connection. For example:
Previous
IPEndPoint myEndpoint = new IPEndPoint(IPAddress.Parse(_serverAddress), _port);
_serverSocket = new Socket(myEndpoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
_serverSocket.Bind(myEndpoint);
_serverSocket.Listen((int)SocketOptionName.MaxConnections);
_serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), _serverSocket);
.....
private void AcceptCallback(IAsyncResult result)
{
ConnectionInfo connection = new ConnectionInfo();
try
{
Socket s = (Socket)result.AsyncState;
connection.Socket = s.EndAccept(result);
connection.Buffer = new byte[1024];
connection.Socket.BeginReceive(connection.Buffer,
0, connection.Buffer.Length, SocketFlags.None,
new AsyncCallback(ReceiveCallback),
connection);
}
catch (SocketException exc)
{
CloseConnection(connection, "Exception in Accept");
}
catch (Exception exc)
{
CloseConnection(connection, "Exception in Accept");
}
finally
{
_serverSocket.BeginAccept(new AsyncCallback(AcceptCallback), result.AsyncState);
}
}
By this way client connection count no raize 800
Currently i write this:
IPEndPoint myEndpoint = new IPEndPoint(IPAddress.Parse(_serverAddress), _port);
_serverSocket = new Socket(myEndpoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
_serverSocket.Bind(myEndpoint);
_serverSocket.Listen((int)SocketOptionName.MaxConnections);
acceptThread = new Thread(new ThreadStart(ExecuteAccept));
acceptThread.Start();
......
private void ExecuteAccept()
{
while (true)
{
ConnectionInfo connection = new ConnectionInfo();
try
{
connection.Socket = _serverSocket.Accept();
connection.Buffer = new byte[1024];
connection.Socket.BeginReceive(connection.Buffer, 0, connection.Buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), connection);
}
catch (SocketException exc)
{
CloseConnection(connection, "Exception in Accept");
}
catch (Exception exc)
{
CloseConnection(connection, "Exception in Accept");
}
}
}
By this way client connection count raize over 2000. Read and write i do with BeginXXX and EndXXX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With