|
Polling is one way to identify the listener status. You have to send a message to server and check the delivery status. If message got delivered successfully, server is connected.
Best wishes,
Navaneeth
|
|
|
|
|
Sending the message will induce the listener to recieve it and process.
In the listener I handle specific messages. It will need to process then connection test message in addition?
Do I need to insert additional sending of some data in that loop? with NetworkStream
for (int i = 0; i < 10 * 5; i++)
{
if (networkStream.DataAvailable == true)
{
}
Thread.Sleep(100);
if (tcpClient.Connected == false)
{
break;
}
}
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: In the listener I handle specific messages. It will need to process then connection test message in addition?
Yes. It can just process this message and acknowledge back.
Best wishes,
Navaneeth
|
|
|
|
|
Hi..!!
i add the paint event and both the shapes will be drawn on the form when i
run the progra, just in case if the statement of radio buttons or if() statements are not present. if i write them it don't give any error but only square comes on screen.
if i put this code on form_load then e.graphics is not recognized.what should i do...?????? don't know..plz reply if sumbdy knows...thanxx..
private void Shapes_Paint(object sender, PaintEventArgs e)
{
if (Square.Checked == true)
{
e.Graphics.DrawRectangle(Pens.Blue, 180, 80, 80, 80);
}
if(Triangle.Checked == true)
{
e.Graphics.DrawPolygon(Pens.Red, new Point[] { new
Point(300, 150), new Point(400, 250), new Point(200,250) });
}
}
|
|
|
|
|
Tip: Look at the PRE tags
The e.Graphics field is a Graphics type. To get an instance of this, set the Form's BackgroundImage property to a new Bitmap , passing the Form's ClientHeight and ClientWidth parameters. Then use your normal DrawXXX methods on the result returned from Graphics.FromImage(YourForm.BackgroundImage)
modified on Sunday, November 1, 2009 3:39 AM
|
|
|
|
|
0x3c0 wrote: Tip 2: Use plain English
That's a bit rude. The poster is obviously someone whose first language is not English, but has still tried hard to make their question clear.
|
|
|
|
|
I was a touch cranky last night to be honest. I'm not too happy with the way that sounds, and I agree it was rude. Edited
|
|
|
|
|
It's a trap we can all fall into quite easily - I'm as guilty as anyone. I make it a rule now always to use the preview button on my replies and read through a couple of times before I post. And then I re-read it after posting just in case.
The good thing about these forums is that not only do we police the spammers, but also each other.
|
|
|
|
|
Hi,
you are right, all painting should be done in the Paint handler.
however if your drawing isn't to be constant, you should call Invalidate() when a change is needed.
So here, add CheckedChanged handlers to your checkboxes and have them call Invalidate; you may even share such a handler for many Controls.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
thanx..i got it and iots working now..
|
|
|
|
|
you're welcome.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
iwant to write CSMA/CD with c#
|
|
|
|
|
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
No need to ask. Go ahead, please.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Gosh - it's been a long time since anybody mentioned Carrier Sense Multiple Access with Collision Detection. Good on you. What's your question?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
anooshe wrote: iwant to write CSMA/CD with c#
For what purpose?
|
|
|
|
|
What made you feel you needed to ask for permission ? If you ever have an actual programming question, I suggest you read the guide on how to ask questions, first.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi, I'm making a Bingo Generator for a assignment, but it generates the last number, then should you click the button again it crashes, also crashing VS2010 so I don't get a error either. here's the button code:
var lineCount = 1;
using (var reader = File.OpenText(@"saved.bingo"))
{
while (reader.ReadLine() != null)
{
lineCount++;
}
}
TextWriter saveCalled = new StreamWriter("saved.bingo");
saveCalled.Write(called.Text);
saveCalled.Close();
TextReader loadSaved = new StreamReader("saved.bingo");
string saved = loadSaved.ReadToEnd();
loadSaved.Close();
randomGenerated.generate();
TextReader nextBingo = new StreamReader("bingoNext.bingo");
string bingoNum = nextBingo.ReadToEnd();
nextBingo.Close();
bingoNum = bingoNum.Trim();
if (saved.Contains(bingoNum) == true)
{
randomGenerated.generate();
}
else
{
TextReader tr = new StreamReader("saved.bingo");
string saveNm = tr.ReadToEnd();
tr.Close();
int saveNum = saveNm.Count();
if (saveNum >= 15)
{
button1.Visible = false;
MessageBox.Show("Game Over.");
}
newnum.Text = bingoNum;
TextReader nextCalled = new StreamReader("calledNext.bingo");
string calledNum = nextCalled.ReadToEnd();
nextCalled.Close();
called.Text = calledNum;
}
and the generator code:
namespace openBingo
{
public class randomGenerated
{
public static void generate()
{
System.Random linegrab = new System.Random(DateTime.Now.Millisecond);
TextReader numRead = new StreamReader("numbers.bingo");
ArrayList lines = new ArrayList();
string line;
while ((line = numRead.ReadLine()) != null)
{
lines.Add(line);
}
int randomIndex = linegrab.Next(lines.Count);
string bingoNum = (lines[randomIndex]).ToString();
numRead.Close();
TextReader numbCheck = new StreamReader("saved.bingo");
string saved = numbCheck.ReadToEnd();
saved = saved.Trim();
numbCheck.Close();
if (saved.Contains(bingoNum))
{
randomGenerated.generate();
}
else
{
TextWriter saveNum = new StreamWriter("saved.bingo");
saveNum.WriteLine(bingoNum);
saveNum.Close();
string randBingo = bingoNum;
TextWriter subNum = new StreamWriter("bingoNext.bingo");
subNum.WriteLine(randBingo);
subNum.Close();
string newCalled = saved + " " + randBingo;
TextWriter subCol = new StreamWriter("calledNext.bingo");
subCol.WriteLine(newCalled);
subCol.Close();
}
}
}
}
It also gives no error on compiling either.
Thanks in advance, any more info you need to just say.
Ben.
|
|
|
|
|
Wrap the code in try/catch block and print out the exception.
Best wishes,
Navaneeth
|
|
|
|
|
Hi,
you need to figure out where things go wrong. Start by using a try-catch block, and displaying the exception, all of it. Hence use something along these lines:
try {
} catch (Exception exc) {
Console.WriteLine(exc.ToString());
}
You can do this in the button click handler, in the generate() method, etc.
Then watch the line numbers (and tell Visual to always show them, see here[^])
BTW: your program looks terrible. Many things seem less than good.
- Why are you writing and reading files all the time? Don't you trust the computer's memory?
FYI: there are File methods that read or write all text of a file.
- For random numbers, you should only have a single RNG and call Next on it, instead of creating new ones.
- generate() is recursive. Any idea what keeps it from recursing forever? (which would cause a StackOverflowException).
- and please stop abusing the var keyword, use real types instead.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Hi again,
How would I store something in the computers memory?
Ben.
|
|
|
|
|
Normally you keep the data in variables as long as your app is running; and you save it to disk, if needed, when the app exits.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Haha, I do try, but sometimes i need to use the data of the variable in a diffrent button control or something, and it wont let it.
I tried settting it to something like:
public void button1
but no luck
Thanks,
Ben.
|
|
|
|
|
Ben Magee wrote: I tried settting it to something like:
public void button1
but no luckFrown
I think maybe you need to study the basics of C#.
|
|
|
|
|
Richard MacCutchan wrote: I think maybe you need to study the basics of C#.
Did some studying, I now understand I need a public class with static variables inside to store data.
Thanks for the advice (:
Ben.
|
|
|
|