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. -
try
-
{
-
-
if (state.workSocket != null)
-
{
-
log.DebugFormat("ssl socket displose,{0},{1}", Doomed, IP);
-
state.workSocket.Shutdown(SocketShutdown.Both);
-
state.workSocket.Close(1);
-
state.workSocket = null;
-
log.DebugFormat("ssl socket displose complete,{0},{1}", Doomed, IP);
-
}
-
}
-
catch(Exception e1)
-
{
-
log.DebugFormat("error in ssl socket displose,{0},{1},{2}", Doomed, IP,e1);
-
}
-
-
try{
-
if (state.workSslStream != null)
-
{
-
log.DebugFormat("ssl stream displose,{0},{1}", Doomed, IP);
-
state.workSslStream.Dispose();
-
state.workSslStream = null;
-
}
-
-
}
-
catch (Exception e1)
-
{
-
log.DebugFormat("error in ssl stream displose,{0},{1},{2}", Doomed, IP,e1);
-
}
-
-
state = null;
-
-
}
-
Any ideas?
7 2787 -
-
try
-
{
-
//connect
-
}
-
-
catch
-
{
-
//exception
-
}
-
-
finally
-
{
-
//disconnect
-
}
-
-
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
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
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.
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
tried adding gc.collect() twice , but didn't work
thanks
zoho
what if.. -
try
-
{
-
//connect
-
}
-
catch
-
{
-
//exception
-
}
-
finally
-
{
-
GC.Collect();
-
}
-
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 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;...
|
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");
|
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?...
|
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?
|
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.
| |
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.
|
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...
|
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...
|
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 ...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |