|
If all the computers are on the same LAN, you could use the broadcast address so that any computer can pick up the messages:
Broadcasting Using Socket-Oriented Approach[^]
If they're on different networks, or you don't want the overhead associated with broadcasting, then you'll need to use multicasting:
IP Multicasting in C#[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks! It will probebly be on the same LAN.
|
|
|
|
|
The error occurs when I try to send a message. It occurs on both computers.
When I send from one computer the error shows on the other.
|
|
|
|
|
larsp777 wrote: listMessage.Items.Add("Friend: " + receivedMessage);
I'm guessing that's the line that's causing the problem. The callback method will be called on a background thread; you will need to use InvokeRequired and Invoke to get back to the UI thread when you want to access the form's controls.
Invoke((Func<object, int>)listMessage.Items.Add, "Friend: " + receivedMessage);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you both!
I think that is the problem. Will check it out and get back.
|
|
|
|
|
hey OG, please enlighten me more on this.
|
|
|
|
|
Sorry Rahul, but it's a huge subject - I couldn't begin to do it justice in a small text box!
There are some good tutorials out there which explain threading and the UI pretty well:
http://stuff.seans.com/2009/05/21/net-basics-do-work-in-background-thread-to-keep-gui-responsive/[^] (Backgound and why to thread)
http://www.dreamincode.net/forums/topic/246911-c%23-multi-threading-in-a-gui-environment/[^] (Fairly advanced)
But basically when you start to use multiple threads you can't touch any controls, except from the thread that created them - which is called the UI thread (for User Interface) and is the original thread the form started on. If you try, you will get a "cross-threading" error telling you not to do that. The only way to get round it is to Invoke the control - which basically requests the UI thread to do the work for you.
Have a look at the BackgroundWorker thread - it provides a way to update the display without invoking via the ProgressChanged event, which is executed on the original thread.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Can you mark a question as solved.
You really solved it Richard but Griffin also helped.
I am working on a game for XNA and need both computers to have access to the same "board".
Do you know anything about that?
|
|
|
|
|
I am reading file and after validation i am saving data in properties
Now i was hoping to use properties for validation and then save if validation succeed for e.g.
const string AN2Mandatory = @"[a-zA-Z@$^�-9\s\S]{2}";
const string AN70Optional = @"[a-zA-Z@$^�-9\s\S]{70}"; these are for validations
and these are properties
public string VersionNumber { get; set; }
public string ClientName { get; set; }
this is sample logic
Match m = Regex.Match(Line, AN70Optional);
VersionNumber = m.Value;
can i apply attributes or something so that while puting value in property my validation is evaluated first and then fill property. instead of validating separately and then storing it
|
|
|
|
|
I can offer you two ways...
1 - Put the validation into the property setter (simple).
2 - Write (or find) an attribute that gets the regex as parameter and validates the property decorated with (much powerful).
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
i am also trying the 2 approach and for that i have to write a custom attribute.
|
|
|
|
|
Great - when you ready made it into an article to share with all!!!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
This is a win form application
i have created a class
public class ValidateProperty : Attribute
{
string _pattern;
bool _mandatory;
public ValidateProperty(string Pattern, bool Mandatory = false)
{
_pattern = Pattern;
_mandatory = Mandatory;
}
public override bool Match(object obj)
{
Match m = Regex.Match((string)obj, _pattern);
if (_mandatory == true)
{
if (string.IsNullOrWhiteSpace(m.Value)) return false;
else
{
return true;
}
}
else
return true;
}
}
and then applied on property
[ValidateProperty(@"[a-zA-Z@$^-9\s\S]{70}",true)]
public string ClientName { get; set; }
but it is not validating when i put a string with less than 70 char. even in debug mode code is not going to match function
|
|
|
|
|
{70} doesn't mean exactly 70, but up to 70!!!
The correct format of {} is {m,n} where m is from and n is to...
When you use only one number it interpreted as {0,n}.
For exactly 70 characters try {70,70}!!!
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
yeah that's fine but issue is that it is not fired even if i pass null or less than 70 char
less than 70 so it should return false or should not accept value in that property.
but currently it is not happenin
|
|
|
|
|
You attribute's Match method got hit?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
No it does not get hit.
ClientName="dd";
|
|
|
|
|
|
this is good thanks but data i will have is something like this
RA01XYZ 201401231445012345611012345678998765432101234DESTINATIONNAMESIZEIS70
RA is one field
01 is one field
XYZ is on and so on
so i will have to extract and then validate
any suggestions
|
|
|
|
|
With regex you can validate without breaking it apart...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
yeah but then we will have to validate through regex and store it in property separately
i guess this is what they call catch 22
|
|
|
|
|
I think not.
You should pass the regex as a property to your new attribute...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
that's what i am doing
but see
i need to first
extract
validate
store
[RegexValidator(@"[a-zA-Z@$^-9\s\S]{2}", ErrorMessage = "ok")]
public string RecordType { get; set; }
[RegexValidator(@"[a-zA-Z@$^-9\s\S]{2}",ErrorMessage="ok1")]
public string VersionNumber { get; set; }
[StringLengthValidator(1, 50, MessageTemplate = "Last Name must be between 1 and 70 characters")]
public string ClientName { get; set; }
-----------------
string Line="RA01XYZ 201401231445012345611012345678998765432101234DESTINATIONNAMESIZEIS70 SENDINGENTITYIDENTIFIER SENDERNAMESIZE70 ";
p.RecordType = Line;
p.VersionNumber = Line;
Now issue is that it will always start from 1 character it will not increment
RecordType will start from 1 to 2
so VersionNumber should start from 3 to 4
and ClientName from 5 to 50
i guess i'll try mentioning this using StringLength validator but then datatype validation will be a case
|
|
|
|
|
|
thanks
now i guess i cant do evs in one step so i am extracting first using substring
and then validating and storing using attributes [EL]
[RegexValidator(@"[a-zA-Z@$^-9\S]{2}", MessageTemplate = "RecordType Validation failed")]
|
|
|
|