HI,
I have developed C# socket server using SSLStream . I followed MSDN examples on developing it. I am having few issues
1.The memory keep on increasing on more number of clients connected.
2.It is not accepting new clients after sometime, may be after few days, eventhough already connected clients are sending and receiving data.
When I do netstat -a , I see tcplistener is listening at port but when I do telenet [server] [port] , returns with could not make connection to specified port.But restarting the server fixes the issue and accepts new clients as well.
Thanks
Any ideas?
Thanks
3 4942
It would help us if you were to show the code you're having issues with, and a better description of the issue(s) you're having. NOTE: Please use code tags when posting your code :)
Here is the code to accept the connections - public void Start(int Port)
-
{
-
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, Port);
-
// create the listener which listens for incoming connections
-
listener = new TcpListener(localEndPoint);
-
listener.Start();
-
//Accept connections asynchronously
-
listener.BeginAcceptSocket(acceptCallBack, listener);
-
-
}
-
-
public void Stop()
-
{
-
try
-
{
-
if (listener!=null)
-
listener.Stop();
-
listener = null;
-
}
-
catch { }
-
}
-
-
public void OnAccept(IAsyncResult result)
-
{
-
TcpListener listener = null;
-
SslStream sslStream = null;
-
try
-
{
-
listener = result.AsyncState as TcpListener;
-
client = listener.EndAcceptSocket(result);
-
listener.BeginAcceptSocket(acceptCallBack, listener);
-
log.DebugFormat("client cert required:{0},CheckCertifcateRevocation:{1} ", clientCertificateRequired,ConfigurationManager.AppSettings["CheckCertifcateRevocation"]);
-
if (clientCertificateRequired)
-
{
-
sslStream = new SslStream(new NetworkStream(client, false), false, remoteCertValidation);
-
}
-
else
-
{
-
sslStream = new SslStream(new NetworkStream(client, false), false);
-
}
-
sslStream.BeginAuthenticateAsServer(serverCertificate, clientCertificateRequired, SslProtocols.Default, Convert.ToBoolean(ConfigurationManager.AppSettings["CheckCertifcateRevocation"]), authenticationCallBack, sslStream);
-
}
-
catch (Exception ex)
-
{
-
if (sslStream != null)
-
{
-
sslStream.Dispose();
-
sslStream = null;
-
-
}
-
log.ErrorFormat("After accepting client {0} connection :{1}",client.RemoteEndPoint.ToString(), ex.Message);
-
return;
-
}
-
}
-
-
public void OnAuthenticate(IAsyncResult result)
-
{
-
-
-
SslStream sslStream = null;
-
StateObject state = null;
-
try
-
{
-
sslStream = result.AsyncState as SslStream;
-
sslStream.EndAuthenticateAsServer(result);
-
-
maxNumberAcceptedClients.WaitOne();
-
log.InfoFormat("SSL authenticated, Encrypted: {0}, Signed: {1}", sslStream.IsEncrypted, sslStream.IsSigned);
-
-
Interlocked.Increment(ref numConnectedSockets);
-
PerformanceCounters.SSLConnections.RawValue = numConnectedSockets;
-
PerformanceCounters.SSLTotalConnections.Increment();
-
-
string IP = "?.?.?.?";
-
-
try
-
{
-
IP = client.RemoteEndPoint.ToString();
-
}
-
-
catch { }
-
log.InfoFormat("[{0}]\topened SSL client: #{1} connected", IP, numConnectedSockets);
-
state = new StateObject();
-
state.workSocket = client;
-
state.workSslStream = sslStream;
-
ConnectionBase connection = (ConnectionBase)Activator.CreateInstance(ClientType, this, state);
-
-
}
-
catch (Exception ex)
-
{
-
-
if (sslStream != null)
-
{
-
log.ErrorFormat("authentication exception for the client: {0}",client.RemoteEndPoint.ToString());
-
sslStream.Dispose();
-
sslStream = null;
-
}
-
state = null;
-
log.DebugFormat("Exception In authentication: {0}", ex);
-
return;
-
}
-
-
}
-
-
-
Thanks
Any body who knows about sockets with sslstream?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: zbcong |
last post by:
Hello:
I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a...
|
by: zhebincong |
last post by:
Hello:
I write a multithread c# socket server,it is a winform application,there is
a richtextbox control and button,when the button is click,the server begin
to listen the socket port,waiting...
|
by: Colin |
last post by:
I'm writing a little console socket server but I'm having some
difficulty. Can I ask your advice - where is the best place to get
some help on that topic? It would be nice if some people who knew...
|
by: Macca |
last post by:
Hi,
I have a synchronous socket server which my app uses to read data from
clients.
To test this I have a simulated client that sends 100 byte packets.
I have set up the socket server so...
|
by: Macca |
last post by:
Hi,
I am writing an asychronous socket server to handle 20+ simulataneous
connections.
I have used the example in MSDN as a base. The code is shown at end of
question.
Each connection has a...
|
by: Chris Mullins |
last post by:
One of the things I've spent the last several years working on is a highly
scalable socket server written in C#.
The SoapBox Server has recently been tested to well over 100k simultanous
users....
|
by: zxo102 |
last post by:
Hi everyone,
I am using a python socket server to collect data from a socket
client and then control a image location ( wxpython) with the data,
i.e. moving the image around in the wxpython frame....
|
by: Engineerik |
last post by:
I am trying to create a socket server which will listen for connections from
multiple clients and call subroutines in a Fortran DLL and pass the results
back to the client. The asynchronous socket...
|
by: doc |
last post by:
Hi
Hard to know where to post this and I don't want to double post it - please move it if you need to,
I am trying to connect a Flash client socket (XML) to a php socket server (using Flash 8 and...
|
by: bartosz.zaleski |
last post by:
Hi
I am running the PHP Socket Server:
#!/usr/bin/php -q
<?php
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |