473,327 Members | 2,025 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,327 software developers and data experts.

socket server memory is keep on increasing

11
Hi,

We have socket server which is developed in c# .net 3.5.
I see server memory keep on increasing whenver client disconnectes and connects.The server disconnects client if client didn;t send valid credentials.
When client is trying to connect with invalid credentials the memory is keep on increasing.
Here is the code that handles disconnection.
Expand|Select|Wrap|Line Numbers
  1. try
  2.                         {
  3.  
  4.                             if (state.workSocket != null)
  5.                             {
  6.                                 log.DebugFormat("ssl socket displose,{0},{1}", Doomed, IP);
  7.                                 state.workSocket.Shutdown(SocketShutdown.Both);
  8.                                 state.workSocket.Close(1);
  9.                                 state.workSocket = null;
  10.                                 log.DebugFormat("ssl socket displose complete,{0},{1}", Doomed, IP);
  11.                             }
  12.                         }
  13.                         catch(Exception e1)
  14.                         {
  15.                             log.DebugFormat("error in ssl socket displose,{0},{1},{2}", Doomed, IP,e1);
  16.                         }
  17.  
  18.                         try{
  19.                             if (state.workSslStream != null)
  20.                             {
  21.                                 log.DebugFormat("ssl stream displose,{0},{1}", Doomed, IP);
  22.                                 state.workSslStream.Dispose();
  23.                                 state.workSslStream = null;
  24.                             }
  25.  
  26.                         }
  27.                         catch (Exception e1)
  28.                         {
  29.                             log.DebugFormat("error in ssl stream displose,{0},{1},{2}", Doomed, IP,e1);
  30.                         }
  31.  
  32.                        state = null;
  33.  
  34.                     }
  35.  
Any ideas?
Apr 23 '12 #1
7 2762
Expand|Select|Wrap|Line Numbers
  1.  
  2. try
  3. {
  4. //connect
  5. }
  6.  
  7. catch
  8. {
  9. //exception
  10. }
  11.  
  12. finally
  13. {
  14. //disconnect
  15. }
  16.  
  17.  
Apr 24 '12 #2
RhysW
70
the above code would mean everytime someone connects they disconnect immediately afterwards, don't put it in a block like that

rekedtechie, things in the finally block are ALWAYS executed, regardless of what happens in the try or catch, with this example the user would connect, may or may not throw an exception, then would be forcibly disconnected the moment it touched on the finally block.

On topic, perhaps the sockets are not being properly closed, thus each time a new one is opened it increases the memory to allow for it to connect, that's the only thing i can think of that might be happening, if you step through your code in debug mode you might be able to isolate the line or lines of code that are increasing the memory
Apr 24 '12 #3
zoho
11
The code I mentioned is only for Disconnect.The disconnect function is being called in read and write operations whenever there is IO xceptionsor clients are being diconnected.

After disconnect I ran netstat command , I don;t see any connections.

Thanks
Apr 24 '12 #4
Plater
7,872 Expert 4TB
Is the SSLStream a wrapper around the socket stream? Should you be disposing of that first?

You can try inserting this code(yes doubled)
GC.Collect();GC.Collect();

It is not a solution, but it can be helpful in finding problems. It will force the garbage collect to free up memory. If calling that code drops your memory down, you probably have half-references to objects somewhere.
I don't have a better way to explain that, but looking up memory management and best practices (and how the GC works) will be helpful.
Apr 27 '12 #5
zoho
11
Yep, I am disposing sockets first and then ssl stream.I tried using tcpClient.getStream too instead of socket stream , still no luck.
I will try adding GC.Collect();twice and see what happens.

Thanks
Apr 27 '12 #6
zoho
11
tried adding gc.collect() twice , but didn't work

thanks
zoho
Apr 28 '12 #7
what if..
Expand|Select|Wrap|Line Numbers
  1. try
  2. {
  3. //connect
  4. }
  5. catch
  6. {
  7. //exception
  8. }
  9. finally
  10. {
  11. GC.Collect();
  12. }
  13.  
Apr 29 '12 #8

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...
0
by: Coco | last post by:
I have a active user counter in my web apps which previously works but now i realise the counter keep increasing. the value of active user is kept in the global.asax which i do increase during...
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.