473,799 Members | 3,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

socket server memory is keep on increasing

11 New Member
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 2787
rekedtechie
51 New Member
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 New Member
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 New Member
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 Recognized Expert Expert
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 New Member
Yep, I am disposing sockets first and then ssl stream.I tried using tcpClient.getSt ream too instead of socket stream , still no luck.
I will try adding GC.Collect();tw ice and see what happens.

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

thanks
zoho
Apr 28 '12 #7
rekedtechie
51 New Member
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
7091
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 incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1"); private IPEndPoint myServer; private Socket socket; private Socket accSocket; private System.Windows.Forms.Button button2;...
2
26521
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 for a incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1");
0
948
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 session start and descrease when session end i am worried it might be a issues for the server as i use session to store some data but the counter is definately wrong becuase i know it's far too high what could be wrong and how do i resolve that?...
7
2389
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 what they were doing could take a look at my code and tell me where and why I'm going wrong. Any suggestions of groups or forums?
9
3609
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 that its buffer is bigger than this. I did this expecting the data to be read in one pass.
0
4694
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 number of different types of data coming in. I have a databuffer for each type of data coming in.
8
4116
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. This means it's handling 100k TCP connections on a Windows Platform without any trouble at all. I finally got around to writing a blog post that describes the different architectures we've gone through, and the pros and cons of each. All of...
9
5559
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. But the "app.MainLoop()" in wxpython looks like conflicting with the "while 1:" in socket server. After I commented the "app.MainLoop()", everything is working except two things: 1. if I click anywhere on the screen with the mouse, the image is...
4
3607
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 client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
0
2421
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 php 5). My php socket server responds correctly when I connect to it with a php client socket but I cannot connect with the flash xml client socket. Both codes are included below - they are both in the same folder on the web site and I am only...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.