473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Scalable SSL socket server

11
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
Mar 27 '12 #1
3 4942
PsychoCoder
465 Expert Mod 256MB
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 :)
Mar 27 '12 #2
zoho
11
Here is the code to accept the connections

Expand|Select|Wrap|Line Numbers
  1. public void Start(int Port) 
  2.     { 
  3.         IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, Port); 
  4.         // create the listener which listens for incoming connections 
  5.         listener = new TcpListener(localEndPoint); 
  6.         listener.Start();  
  7.         //Accept connections asynchronously 
  8.         listener.BeginAcceptSocket(acceptCallBack, listener); 
  9.  
  10.     } 
  11.  
  12.     public void Stop() 
  13.     { 
  14.         try 
  15.         { 
  16.             if (listener!=null)  
  17.                 listener.Stop(); 
  18.             listener = null; 
  19.         } 
  20.         catch { } 
  21.     } 
  22.  
  23.     public void OnAccept(IAsyncResult result) 
  24.     { 
  25.         TcpListener listener = null; 
  26.         SslStream sslStream = null; 
  27.         try 
  28.         { 
  29.             listener = result.AsyncState as TcpListener; 
  30.             client = listener.EndAcceptSocket(result); 
  31.             listener.BeginAcceptSocket(acceptCallBack, listener); 
  32.             log.DebugFormat("client cert required:{0},CheckCertifcateRevocation:{1} ", clientCertificateRequired,ConfigurationManager.AppSettings["CheckCertifcateRevocation"]); 
  33.             if (clientCertificateRequired) 
  34.             { 
  35.                 sslStream = new SslStream(new NetworkStream(client, false), false, remoteCertValidation); 
  36.             } 
  37.             else 
  38.             { 
  39.                 sslStream = new SslStream(new NetworkStream(client, false), false); 
  40.             } 
  41.             sslStream.BeginAuthenticateAsServer(serverCertificate, clientCertificateRequired, SslProtocols.Default, Convert.ToBoolean(ConfigurationManager.AppSettings["CheckCertifcateRevocation"]), authenticationCallBack, sslStream); 
  42.         } 
  43.         catch (Exception ex) 
  44.         { 
  45.             if (sslStream != null) 
  46.             { 
  47.                 sslStream.Dispose(); 
  48.                 sslStream = null; 
  49.  
  50.             } 
  51.             log.ErrorFormat("After accepting client {0} connection :{1}",client.RemoteEndPoint.ToString(), ex.Message); 
  52.             return; 
  53.         } 
  54.     } 
  55.  
  56.     public void OnAuthenticate(IAsyncResult result) 
  57.     { 
  58.  
  59.  
  60.         SslStream sslStream = null; 
  61.         StateObject state = null; 
  62.         try 
  63.         { 
  64.             sslStream = result.AsyncState as SslStream; 
  65.             sslStream.EndAuthenticateAsServer(result); 
  66.  
  67.             maxNumberAcceptedClients.WaitOne(); 
  68.             log.InfoFormat("SSL authenticated, Encrypted: {0}, Signed: {1}", sslStream.IsEncrypted, sslStream.IsSigned); 
  69.  
  70.             Interlocked.Increment(ref numConnectedSockets); 
  71.             PerformanceCounters.SSLConnections.RawValue = numConnectedSockets; 
  72.             PerformanceCounters.SSLTotalConnections.Increment(); 
  73.  
  74.             string IP = "?.?.?.?"; 
  75.  
  76.             try 
  77.             { 
  78.                 IP = client.RemoteEndPoint.ToString(); 
  79.             } 
  80.  
  81.             catch { } 
  82.             log.InfoFormat("[{0}]\topened SSL client: #{1} connected", IP, numConnectedSockets); 
  83.             state = new StateObject(); 
  84.             state.workSocket = client; 
  85.             state.workSslStream = sslStream; 
  86.             ConnectionBase connection = (ConnectionBase)Activator.CreateInstance(ClientType, this, state); 
  87.  
  88.         } 
  89.         catch (Exception ex) 
  90.         { 
  91.  
  92.             if (sslStream != null) 
  93.             { 
  94.                 log.ErrorFormat("authentication exception for the client: {0}",client.RemoteEndPoint.ToString()); 
  95.                 sslStream.Dispose(); 
  96.                 sslStream = null; 
  97.             } 
  98.             state = null; 
  99.             log.DebugFormat("Exception In authentication: {0}", ex); 
  100.             return; 
  101.         } 
  102.  
  103.     } 
  104.  
  105.  
  106. Thanks
Mar 27 '12 #3
zoho
11
Any body who knows about sockets with sslstream?
Mar 28 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
2
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...
7
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...
9
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...
0
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...
8
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....
9
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....
4
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...
0
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...
4
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();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.