|
The problem is that this error is occurring on the server. There are a lot of clients connected to it and the clients stay connected.
|
|
|
|
|
If the error is occuring on the server then one of the client's actively closed their socket. This happens when the client closes the socket or the process crashes (in which case the kernel closes out the socket).
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
Maybe there is another problem. Look what is happening: I have the following methods:
internal void SendData(Channel channel, byte[] buffer, int offset, int count)
{
if(channel != null && channel.Socket != null && channel.Socket.Connected)
channel.Socket.BeginSend(buffer, offset, count, SocketFlags.None, new AsyncCallback(OnDataSent), channel);
}
private void OnDataSent(IAsyncResult asyncResult)
{
if(asyncResult != null && asyncResult.AsyncState != null)
{
Channel channel = (Channel)asyncResult.AsyncState;
ushort bytesSent = (ushort)channel.Socket.EndSend(asyncResult);
...
}
}
The Channel class is a custom class that holds a reference to a Socket object. First I call the SendData method, that calls the BeginSend method on the Socket object. When the socket ends sending the data, it calls the OnDataSent method. The problem is that when I try to call the EndSend method, the Socket object is null. I don't have any control over it once is the framework that calls the method. When I don't test if the Socket object is a null reference, I get the NullReferenceException. When I test, I get the other exception (the SocketException).
In other words, all the problems reside in the fact that the Socket object is null. Do you have any idea about what could be causing this behaviour? Could the network topology have any influence?
Thanks.
|
|
|
|
|
This looks like it may be a race condition. OnDataSend is called on a different thread than BeginSend. Is your Channel class thread safe?
When you say test and not testing your app are referring to attaching a debugger? If so then it's almost certainly a race condition.
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
I have been reading from various sources about delegates. The more I read the more I get confused.
My question is - What can you do with delegates that you cannot do with just calling the method and not using delegate(s) howsoever?
I mean assume that when an event occurs then instead of having a delegate call the method just call the method directly from the event handler.
Also if you can send any good link that explains the concept it will be appreciated.
Thanks
----------
Venus Patel
http://patelsinc.blogspot.com/
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
I am sure there are other advantages, but the one that comes to mind is this:
Say you create a control dynamically. Since it is not created at design time, you have no other way to associate your sub with your control. What you need to do is create your delegate, and when you create your control at runtime, associate the delegate with the controls method call.
Hope this helps.
Roy.
|
|
|
|
|
Why are delegates used instead of just calling the function in the event handler. There are plenty of reasons. Note that delegates are used to bind functions to events, or to call other objects and functions async.
Lets first explain the first, because of delegates you can add more then one listener to the event. This is usefull in multiview application.
The second one is, at least for me, the most important reason. Thanks to the delegate you will be ably to dynamicly invoke a method. This means that a call to the function will be made, but not executed straight away. So the function calling the delegate continues executing its code.
|
|
|
|
|
Gerben I think your second reason is wrong while the calling method whether directly or using its delegate run in the same thread as caller function, it doesn't continue to next statement until the called method(s) return.
---
"Art happens when you least expect it."
|
|
|
|
|
If you invoke a methond dynamicly, even if they operate in the same thread, the running function will not get interrupted. This is because using dynamic invoke you post a message to your application with the request to execute a function. You do not call the function directly.
Also see: MSDN Article on dynamic invokes.
PS: I tried it in a single thread application just to be sure.
|
|
|
|
|
Yes, I see. So it is one other usage of delegates.
Thank you
---
"Art happens when you least expect it."
|
|
|
|
|
Let me add some notes:
1. A Delegate is a type that is used to construct delegate objects that refrence functions with the same signature as delegate.
Just like classes that construct objects.
2. When a delegate object is created with some function name in its constructor, that object will be indirect agent of that function, and this happens RUNTIME. It is important because when you create a compiled class for your users you don't know what functions they will create to bind as their callbacks or event handlers so you call them directly, so there should be some indirect way for them to introduce their functions and that is Delegate!
I hope that is useful
- Mohammad
---
"Art happens when you least expect it."
-- modified at 1:06 Tuesday 13th December, 2005
|
|
|
|
|
Hi buddies,
I have created a remote object in another AppDomain, after a short time of inactivity it seems to be disconnected and removed because next time I call some method on it, an exception says that the object doesn't exists or it is disconnected.
How can I set lifetime of remote objects? May I set it to live till I explicitly remove it ?
Thank you so much,
- Mohammad
---
"Art happens when you least expect it."
|
|
|
|
|
|
Thank you so much leppie, you have helped me lots of times, I hope I can help u back someday buddy
---
"Art happens when you least expect it."
|
|
|
|
|
|
Hi,
I m new to socket programming and c#.I have been trying to write a simple telnet client which will connect to the machine and execute commands and anle to get back the results.I have been so far able to coonect using TcpClient , but I m getting garbage value in return like %??% etc.
Is there any sample code I can follow or please advise me which class I should follow to process the data obtained from the server ? Currently I m using netStream and read and write methods.
Thanks
- P
|
|
|
|
|
The reason you are getting those garbage characters back is that they are formatting codes for telnet. They are attempting to talk to your program and negotiate a common set of features or telling you how to display a certain character.
There's no easy answer here. You'll have to read the Telnet RFC (Request for comments). It details what these codes are and how you should handle them (and also which ones you can ignore).
http://www.faqs.org/rfcs/rfc854.html[^]
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
Hi friends:
I wrote a component in C#(derived from System.ComponentModel.Component).
Now, i want use this component in a COM+ Application with pooling objects
but i have samples of componentServiced, and all classes derived from System.EnterpriseServices.ServicedComponent
can you tellme why the serviced component does not inherit of System.ComponentModel.Component or System.ComponentModel.IComponent ????
thanks in advance
|
|
|
|
|
Hi,
I need a help.
I'm creating a datagid .
It has 4 columns.
On the page load event I called the stored procedure which returns 7 fields out of which i should display 4 columns.
First column was has radiobutton, second,third & 4 th are labels.
the value returned by stored procedure is got in a typed dataset.
There is a field called group id , based on this i need to group rows in datagrid.If a particular group id exists for more than 1 the seond column of the datagrid alone has multiple values seperated by lines , 1st , 3rd & 4th columns have single value.
How can I do this.
Thanks in advance
Regards
Priya
|
|
|
|
|
You're really unspecific as to what you want. Is there any way you could present us with a sample returned dataset, and how you would like it displayed(even if its just typed and spaced accordingly). This would give me more information so I could point you in the direction of resources where you could get the most help.
|
|
|
|
|
Hi,
I want to write a program which will modify the inbound HTML in the IE 6.0. It will capture the inbound HTML before it gets displayed, make some modifications in it and display it in the IE. Can anybody tell me how to achieve this?
The typical flow will be - User will enter the URL in the Internet explorer
Address Bar. The incoming HTML will be read by my program before it gets
displayed. My program will modify some strings - say phone numbers in it and
display the modified HTML.
Technology is not a restriction. I am ready to use VC++ or .NET. Do I have
to use shell Extension? If yes, which interface/event will be helpful?
Thanks in advance.
Regards,
Sunil
|
|
|
|
|
Hello!
That's kinda easy to implement:
Just capture the "DownloadComplete"-event, get the Document-property and then the outertext-property of the body... Change the values and write it back to the outertext-property:
private void m_Browser_DownloadComplete(object sender, System.EventArgs e)
{
IHTMLDocument2 loDocument = (IHTMLDocument2)this.m_Browser.Document;
string lsHtml = Document.body.outerHTML;
// make changes
Document.body.outerHTML = lsHtml;
}
In the above shown example, you can see that it just change the body. Another thing is, that you won't see it in the source-code when you open the source-file with the IE context menue. To change the whole file (and document)... you can write an HTML-file back with the write-methode of the browser component. Don't forget to clear the document object with the clear-methode, b4 you load a new one!
I hope I could help you!
Marcel Erz
-- modified at 9:10 Monday 12th December, 2005
|
|
|
|
|
Hi,
I have some more doubts. As I am novice to all these things, please excuse me if I am talking some non sense.
As per my understanding, above solution assumes that the IE control is embedded in the application. In my case, IE will be invoked from Desktop and I want to capture any HTML which is loaded in that the browser loaded from Desktop. The HTML also might not be mine. It can be loaded by giving any URL like www.google.com or www.msn.com etc. So do I have to get the instance of the Internet Explorer which is invoked from Desktop? If yes, how to get the instance of it?
Thanks,
Sunil
|
|
|
|
|
Hi!
Here is an example to catch all running instances:
public void FindIE() {
// Retrieve list of all IE instances
SHDocVw.ShellWindows loIEs = New SHDocVw.ShellWindows();
SHDocVw.InternetExplorer loIE = null;
int llCount = 0;
mshtml.IHTMLDocument2 loDocument = null;
URLList.Items.Clear();
TitleList.Items.Clear();
IECountText.Text = loIEs.Count;
while(llCount <= loIEs.Count) {
loIE = loIEs.Item(llCount);
llCount++;
if (loIE != null) {
URLList.Items.Add(loIE.LocationURL);
loDocument = (mshtml.IHTMLDocument2)loIE.Document;
if (loDocument != null) {
TitleList.Items.Add(loDocument.title);
}
}
}
}
URLList -> List of all URLs open from instaces
TitleList -> List of all title tag data of all opened documents in the instances
IECountText -> Amount of Instances found
The "SHDocVw.ShellWindows" retrieve all instances of the IE. When every instance get created, it sign in to this list automatically, thats why you have an overview of all IE instances.
"SHDocVw.InternetExplorer" is one instance of an IE. With this, you can kinda do everything what you can do with the browser inside your application. Here an example of changing html of all instances:
public void ChangeAllIE() {
// Retrieve list of all IE instances
SHDocVw.ShellWindows loIEs = New SHDocVw.ShellWindows();
SHDocVw.InternetExplorer loIE = null;
int llCount = 0;
mshtml.IHTMLDocument2 loDocument = null;
URLList.Items.Clear();
TitleList.Items.Clear();
IECountText.Text = loIEs.Count;
while(llCount <= loIEs.Count) {
loIE = loIEs.Item(llCount);
llCount++;
if (loIE != null) {
URLList.Items.Add(loIE.LocationURL);
loDocument = (mshtml.IHTMLDocument2)loIE.Document;
if (loDocument != null) {
loDocument.clear();
loDocument.writeln((object)"Changed html!");
loDocument.close();
}
}
}
}
I hope it is clear so far and it works like I said, coz cannot check it at the moment! I will try it tomorrow morning, but I think it will work! If you need more help, just post it here!
Marcel Erz
P.S.: Plz try to understand the code, and not just copy it. The best way to learn is, to read and understand code!
|
|
|
|
|
Hi Marcel,
Thank you for your reply and sample code. I have one more query. I want to create a toolbar for the Internet Explorer which will have controls like drop down and push buttons. I need to write the program in C#. Can you give me some direction in this regard?
Thanks in advance.
Sunil
|
|
|
|