473,382 Members | 1,380 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,382 software developers and data experts.

Client receives messages even after discoonected?

Hi,
I set up an client to asynchronously receive data from it's connection.
When i'm finished, i close the client using

try
{
theClient.SetSocketOptionSocketOptionLevel.Socket, SocketOptionName.NoDelay,1);
theClient.Shutdown(SocketShutdown.Both);
theClient.Close();
theClient=null;
}

However, somehow the server seems to be able to send me messages !?
Does anyone have any idea how this is happening?
Thanks,
Shaun

Mar 13 '07 #1
4 1287
VJ
Are you running it on a different thread? If you are then the client will
not Garbage collect until all it associated objects are marked to be
disposed. The client is still holding some reference that is not cleaned
up..

VJ

"ShaunO" <Sh****@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
Hi,
I set up an client to asynchronously receive data from it's connection.
When i'm finished, i close the client using

try
{
theClient.SetSocketOptionSocketOptionLevel.Socket, SocketOptionName.NoDelay,1);
theClient.Shutdown(SocketShutdown.Both);
theClient.Close();
theClient=null;
}

However, somehow the server seems to be able to send me messages !?
Does anyone have any idea how this is happening?
Thanks,
Shaun

Mar 13 '07 #2
Yes i am running it on a separate thread to the main app.
I thought that marking it as null would cause the grabage collection.
... clearly not.
How should i go about ensuring it is removed immediately?

What state is the socket in at the end of the function ?- I would have
thought that the closing of the socket would do exactly that - but the new
data is still getting through !!??

Thanks,
Shaun

"VJ" wrote:
Are you running it on a different thread? If you are then the client will
not Garbage collect until all it associated objects are marked to be
disposed. The client is still holding some reference that is not cleaned
up..

VJ

"ShaunO" <Sh****@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
Hi,
I set up an client to asynchronously receive data from it's connection.
When i'm finished, i close the client using

try
{
theClient.SetSocketOptionSocketOptionLevel.Socket, SocketOptionName.NoDelay,1);
theClient.Shutdown(SocketShutdown.Both);
theClient.Close();
theClient=null;
}

However, somehow the server seems to be able to send me messages !?
Does anyone have any idea how this is happening?
Thanks,
Shaun


Mar 13 '07 #3
VJ
Where are you creating the socket? Main or in the secondary thread?, You
cant create the client in secondary thread, and clean up in main thread.
Well the code might work if you have it public and such, but Garbage
collection cannot happen...

it is going to be very hard for me to suggest a clean up idea, without
looking at the code. Can you give me a sketch of what you are doing in the
Main thread and in the secondary thread.. that will help us to see if we can
get some place.

VJ

"ShaunO" <Sh****@discussions.microsoft.comwrote in message
news:D0**********************************@microsof t.com...
Yes i am running it on a separate thread to the main app.
I thought that marking it as null would cause the grabage collection.
.. clearly not.
How should i go about ensuring it is removed immediately?

What state is the socket in at the end of the function ?- I would have
thought that the closing of the socket would do exactly that - but the new
data is still getting through !!??

Thanks,
Shaun

"VJ" wrote:
>Are you running it on a different thread? If you are then the client will
not Garbage collect until all it associated objects are marked to be
disposed. The client is still holding some reference that is not cleaned
up..

VJ

"ShaunO" <Sh****@discussions.microsoft.comwrote in message
news:85**********************************@microso ft.com...
Hi,
I set up an client to asynchronously receive data from it's connection.
When i'm finished, i close the client using

try
{
theClient.SetSocketOptionSocketOptionLevel.Socket, SocketOptionName.NoDelay,1);
theClient.Shutdown(SocketShutdown.Both);
theClient.Close();
theClient=null;
}

However, somehow the server seems to be able to send me messages !?
Does anyone have any idea how this is happening?
Thanks,
Shaun



Mar 13 '07 #4
VJ,
Thanks for you thoughts.
I have the following class structure

ClientManager
-AsynchronousClientSocket
--Socket (Mirosoft class)

following your thoughts i have changed the AsynchronousClientSocket.Stop()
class to be as follows:

theClient.SetSocketOption(SocketOptionLevel.Socket ,SocketOptionName.NoDelay,1);
theClient.SetSocketOption(SocketOptionLevel.Socket ,
System.Net.Sockets.SocketOptionName.DontLinger, 1); // added 160307
theClient.Shutdown(SocketShutdown.Both);
theClient.Close();
theClient=null;
state.workSocket=null; // added 160307
state=null;// added 160307

GC.Collect();
GC.WaitForPendingFinalizers();

Using a memory profiler, i can now see that the only link to the socket that
is still in existance is one from
OverlappedAsyncResult
that is referrenced from
AsyncCallback
that is referrenced from
Socket.BeginReceive

Does this help you to help me?
Thanks,
Shaun

"VJ" wrote:
Where are you creating the socket? Main or in the secondary thread?, You
cant create the client in secondary thread, and clean up in main thread.
Well the code might work if you have it public and such, but Garbage
collection cannot happen...

it is going to be very hard for me to suggest a clean up idea, without
looking at the code. Can you give me a sketch of what you are doing in the
Main thread and in the secondary thread.. that will help us to see if we can
get some place.

VJ

"ShaunO" <Sh****@discussions.microsoft.comwrote in message
news:D0**********************************@microsof t.com...
Yes i am running it on a separate thread to the main app.
I thought that marking it as null would cause the grabage collection.
.. clearly not.
How should i go about ensuring it is removed immediately?

What state is the socket in at the end of the function ?- I would have
thought that the closing of the socket would do exactly that - but the new
data is still getting through !!??

Thanks,
Shaun

"VJ" wrote:
Are you running it on a different thread? If you are then the client will
not Garbage collect until all it associated objects are marked to be
disposed. The client is still holding some reference that is not cleaned
up..

VJ

"ShaunO" <Sh****@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
Hi,
I set up an client to asynchronously receive data from it's connection.
When i'm finished, i close the client using

try
{
theClient.SetSocketOptionSocketOptionLevel.Socket, SocketOptionName.NoDelay,1);
theClient.Shutdown(SocketShutdown.Both);
theClient.Close();
theClient=null;
}

However, somehow the server seems to be able to send me messages !?
Does anyone have any idea how this is happening?
Thanks,
Shaun



Mar 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Adam | last post by:
Hi, I'm having difficulties creating a client application using VB in ASP.NET that receives TCP messages from a VB6 server application. The client sends a message to the server and receives...
1
by: Adam | last post by:
Hi, I'm trying to build a client ASP.NET application in VB.NET that can display messages from a server application as soon as it receives them. These messages from the server have a limited...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
0
by: Janning Vygen | last post by:
Hi, i have a question about how to handle postgresql constraint errors in the client app. I found some mails in the archive about it, too. But i have still so many questions about how to do it,...
1
by: Frank Millman | last post by:
Hi all I am developing a multi-user business/accounting application. It is coming along nicely :-), though rather slowly :-( I have hit an issue which will require a lot of changes to the code...
9
by: John C. Frickson | last post by:
My company produces reports for our customers in PDF format. I have a php script that verifies login status and access rights, and sends the pdf to the client using readfile(). This has worked...
0
by: JYOTIRANJAN | last post by:
Hi All, My Application is developed using C on linux. It is a multithreaded application and 10 threads are waiting for message in pool.Each thread receives message continusly in a while loop from...
1
by: =?Utf-8?B?S2F1c2hhbCBNZWh0YQ==?= | last post by:
Hi, Could you let me know what exactly happens when web service provider receives request from the client (from system perspective, like threading and all) ? Also, how does the web service...
7
by: Anil | last post by:
I have a Javascript program which runs in the browser and has functions work(), and stop(). It listens to commands from the server to work() and can be interrupted by the server to stop(). I am...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.