|
Norman-Timo wrote:
In the case that the client disconnected, my code is waiting for Data and there is logically no dataflow anymore.
Ideally this is what a server should do! Other options:
- poll the client by sending an "empty" packet, a socket exception will occur if the connection is dead.
- ask the client to send some info that it has disconnected, before disconnecting.
top secret xacc-ide 0.0.1
|
|
|
|
|
Yes the server should do so
But I tested this scenario:
I made a connection to the server.
Then I send some data and disconnected from server.
The server was waiting then.
I tried to make another connection from same client, which worked.
But the sended data did´nt reached the server anymore, while he is waiting and waiting...
I think I have to recognize that the connection was disconnected, so that the socket could set to Listen-Mode again and catches the connection witch an Accept() Method.
But while the server is waiting no data transfer is possible anymore.
Yeah polling is maybe a solution, but there should be a property to check if TCP/IP-Partner is available (such like that one on client side with: 'mySocket.Connected' or so...)
So please help me more
Norman-Timo
|
|
|
|
|
Hehe.
There IS a "Socket.Connected" property for Sockets.
I suspect that you are actually WAITING on that socket.
Do not do that. As far as I understand your problem, you have ONE Socket. That is, to say the least, not what anyone expects of a server.
Try understanding the concept of either synchronous sockets OR asynchronous sockets. If you choose the latter, you wont have to do any "manual multi-threading".
My last project at work was also a server waiting on TCP connections.
There is no "worst-case-handling" in there yet, but even if (due to network error or other problems) I lost a few clients, it would not block the whole thing down.
I am using asynchronous sockets, which means at runtime the necessary threads are auto-magically created in a threadpool.
The whole thing is based on the MSDN "non-blockingserverexample".
What you can do to check if your client still is connected: check socket.connection and socket == null (with proper capitalization, of course) or try sending something to your client. You will get an exception if your client is not connected.
I do have one advantage:
Once a client has connected, he will stream his requests one at a time (receive, process, answer - thats what I do) and each request has a length field in the leading five bytes.
So, if a Client has connected, I will immediately receive 13 byte from him, process his request, send my response, then receive the next 13.
I KNOW that a client who did not send me the proper shutdown package and has not responded for, lets say, thirty seconds, must be dead. So I can run over my (yet to be implemented) hashtable every thirty seconds and check for timeouts. That way, it will take less than sixty seconds for any dead sockets to be removed.
|
|
|
|
|
Hey thanx!
But in my case (I forgot to write this!) I only want to communicate with a static partner. And in my case the communication should never be disconnected, and there is only one case if connection fails: socket error.
Only if I start my application I bind the socket to my IPEndpoint and set the Socket to Listen and wait for this client response.
After client is responsing the connection is hold and should never end.
But there are many reasons why the connection breaks: perhaps the cable was disconnected, or the comm. partner has to reboot.....
But nothing helps, so I understand, I have to test the communication and send a "null" package after every certain timespan.
Ok thanx to all Your
Norman-Timo
|
|
|
|
|
In any of the languages like C++, Java, C# there are provisions to cast an object to Type A to an object to Type B. To complicate the matter further, there are various types of casting options provided. It is simple to say and perhaps to imagine the internals when: I (down)cast an integer to float but what happens when I (up)cast? What magic the compiler performs when we cast complex objects to each other.
|
|
|
|
|
No magic! I suggest you read up on polymorphism, inheritance, and numeric conversions, all part of the OO paradigm.
top secret xacc-ide 0.0.1
|
|
|
|
|
The compiler knows how he stores every variable.
The programmer of that compiler just parses for an explicit cast (like (int)myvar) and then says: well, I have to shove these first bits into a new integer-style, then turn them around and here we go....
Casting is all about conversion between different bit arrangements.
Everything is stored as bits in your memory. By declaring variables or designing your class, you also did a description of how these objects or whatever are stored in memory.
Of course, for SOME types, there is no logical conversion. It DOES NOT MAKE SENSE to cast a string into an integer or the other way round.
In these cases, you need to PARSE your stuff, which takes much longer (microcode-wise) than simply rearraning your bits in a given pattern.
Really, just think about it. Everything is bits. You have an signed integer and want to cast it into an unsigned long. What do you have to do?
basically, substract one, then xor with all ones (like 01010011 ^ 11111111)
you then have the "normal" representation of your number, now just remove the sign and...
And so on.
Computers work by rules. If you know these rules, you just have to write them down into a program.
Still, writing a compiler is something I wish I never have to do.
Cheers
Sebs
|
|
|
|
|
Thanks Sebs, this gives some insight. Pretty helpful.
|
|
|
|
|
Thx!
We just need a dynamic array but not a ArrayList
|
|
|
|
|
|
I don´t know what are you exactly looking for (same as leppie)
but there is a IList available, which could dynamicly take objects.
using System.Collections is necessary!
Ciao
Norman-Timo
|
|
|
|
|
Hi,
I want to do lot of Drawing,in my application.I am Doing that on Panel Control palced on Form.One requirement is i want to connect two UserControls on the panel with the line.When UserControls are moved by user line between them should be adjusted accordingly.That line should be Clickable as well so that user will Click on that line and adust the position of that line by draging it,or even he can delete that line.
If i draw that line with CreateGraphics().DrawLine,it will not be clickable??
How can i do this??
Thanks,
TusharM
|
|
|
|
|
hi,
i can smell new visio here.....
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Firstly, just to say.. I've got some experience in C#, mainly scripting components for a MMORPG Emu, so I understand a decent variety of concepts in the language.
However recently I decided to.. ahem.. expand my horizons and branch into outside applications in C#, namely Windows Forms in this case.
I've sort of hit a road block early on with generating the components of my form.
using System;<br />
using System.Windows.Forms;<br />
using System.Drawing;<br />
<br />
namespace Waverian.ScriptGenerator<br />
{<br />
public class ScriptGenForm : Form<br />
{<br />
public ScriptGenForm()<br />
{<br />
InitializeComponent();<br />
<br />
Button b1 = new Button();<br />
b1.Height = 10;<br />
b1.Width = 25;<br />
b1.Text = "Text";<br />
b1.Location = new Point( 15, 15 );<br />
}<br />
<br />
[STAThread]<br />
public static void Main(string[] args)<br />
{<br />
Application.Run(new ScriptGenForm());<br />
}<br />
<br />
#region Windows Forms Designer generated code<br />
private void InitializeComponent()<br />
{<br />
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
this.ClientSize = new System.Drawing.Size(292, 266);<br />
this.Text = "Waverian's Script Generator";<br />
this.Name = "ScriptGenForm";<br />
}<br />
#endregion<br />
}<br />
}
The problem is, even though I've created a button b1, and thought I'd placed it correctly ( in defining location ), when I run the program it only displays the form itself, and not the button.
I've also tried adding components within the InitializeComponent() method, but that also did not produce the button. -.-
Could anybody enlighten me in to how ( or where. I'd assume it was in the constructor ) I'd place a component such as a button?
Cheers,
Waverian.
|
|
|
|
|
hi,
See after creating the control instance you need to add this control to forms(base) controls collection.
Button b1 = new Button();
b1.Height = 10;
b1.Width = 25;
b1.Text = "Text";
b1.Location = new Point( 15, 15 );
this.Controls.Add(b1);
try this
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
I need to allow my application to only be run once. I presume I need to set some sort of system wide flag to do this ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
|
Okay, my project is almost finished and this seems to be the last bug. My error is on line 613 during the last 'while' code. It seems that garbage collection has 'dumped' my initial 'hash' instance??? I then get the error message "Object reference not set to an instance of ans object."!
Q. How do I fix the code to eliminate the error???
try
{
while((line = reader.ReadLine()) != null)
{
string [] tmp = line.Split('\t');
if(tmp.Length == 2)
{
if(!hash.Contains(tmp[0]))
{
hash.Add(tmp[0], tmp[1]);
}
listBox1.Items.Add(tmp[0] + "\t" + tmp[1]);
}
}
}
finally
{
reader.Close();
}
while(myReader2.Read())
{
if (! hash.ContainsKey(str_col_DestIP.Trim()))
{
string strDestDns = "Use Other...";
}
else
{
string str = (hash[1].ToString()); // line 613
}
|
|
|
|
|
It would seem that your Hashtable (I'm assuming that's what 'hash' is) does not have an object stored at the index you're trying to retrieve. Did you mean to say hash[0].ToString() ? Or possibly whatever you're reading in the first while loop contains only one line.
These are only guesses, as not enough code is posted for a definitive answer. The garbage collector won't collect something you still hold a reference to. It's not the hash that's null, though, so that wouldn't be it anyway.
Charlie
if(!curlies){ return; }
|
|
|
|
|
There wouldn't be an item at any index: a Hashtable is not a collection or a list (but can expose them through properties and methods). Coding hash[1] would only work if an object was added to the Hashtable using the integer (Int32 , unless otherwise cast) value 1 for the key.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
D'oh!
Charlie
if(!curlies){ return; }
|
|
|
|
|
No, your hash variable is fine (you should really use a debugger and examine the state of variables in your Autos or Locals window). It's because hash[1] is returning null , which you're trying to call ToString on. Unrolling it, it would look something like this:
object o = hash[1];
o.ToString(); If you added "1" to your Hashtable , then you need to pass "1" - not 1 - to your indexer. They are very different (see the documentation for GetHashCode on any class).
If you're trying to index the second element (remember that in .NET indexes are 0-based) of the Hashtable , you're out of luck. Hash tables don't sort their collections - they use hash keys to store and reference data. You should do a search on google or something for basic theory on hash tables to find out more.
There's never a good reason for NullReferenceException to be thrown, either. When there's a chance that a variable may be null, check it. Even if you could access items like a collection, assuming that's there 2 - or even 1 - element is a bogus assumption. What if the file was empty and you didn't collect any data? There would be nothing in your Hashtable . It would simply be empty.
Software Design Engineer
Developer Division Sustained Engineering, Microsoft
My Articles
|
|
|
|
|
While adding the object in the HashTable hash you have used
hash(tmp[0], tmp[1])
where tmp[0] is a string and also the key value for string object tmp[1]
where as while accessing the hash value you are using hash[1], here key u r using as int (value 1). This is the cause of the error.
Replace the line 613 as below.
if(hash.ContainsKey("1"))
{
string str = hash["1"].ToString();
}
Regards,
Jay
|
|
|
|
|
Well, to draw on a panel, i use:
Graphics pg = panel.CreateGraphics();
pg.FillEllipse( new SolidBrush( Color.Black ), e.X, e.Y,2,2);
Its draw, but, when i minimize the form, the panel is clear!
What can i do to not clear the draw?
Thanks.
|
|
|
|
|
Anytime a window is moved off screen, minimized, or is obstructed from view (by another window) it needs to be repainted then next time it is shown.
In order for your graphics to survive this process, the drawing code needs to be called in response to the Paint event of the control in question (or in an override of OnPaint for a derived control).
Also, when you move the code you posted to the Paint event handler, use the Graphics object supplied in the PaintEventHandler parameter instead of calling CreateGraphics .
Charlie
if(!curlies){ return; }
|
|
|
|
|