|
The well known pair BeginReceiveFrom(),EndReceiveFrom() doesn't seem to work well
if multiple UDP clients from different addresses and/or ports are sending UDP datagrams to
the same socket where a server is listening: the server application accepts only datagrams from
the socket (address + port) which first sent to the receiving socket, all the rest is discarded.
Any suggestion or workaround?
|
|
|
|
|
Have you solved this?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Hi,
I am experimenting a bit with fluent interfaces and decided to try to build a fluent interface to describe a screen layout. I started with an idea of how I wanted the interfaces to work together and mainly focused on intellisense:
<br />
screen.SplitVertical()<br />
.Left.SplitHorizontal()<br />
.Top.CreateRegion("region1")<br />
.Bottom.CreateRegion("region2")<br />
.Right.CreateRegion("main")<br />
.Done();<br />
I wanted to be able to split the screen into two areas (Left/Right, or Top/Bottom) and then define a named region for that area. Or, I should be able to indefinitely split and area into sub-areas. Furthermore, I wanted to guarantee that once a screen was split, both areas had to be defined into a region -- and I wanted intellisense to help me out on that.
So, I built a set of interfaces to make this happen (not worrying about implementation yet). As I was doing this, I ran into an issue that goes a bit beyond my understanding of generics.
First, I thought to compose a bunch of interfaces that contained verbs, or actions, that can be performed. Each interface had a generic parameter that determined the return type of the verb:
<br />
public interface ITop<X> { X Top { get; } }<br />
public interface IBottom<X> { X Bottom { get; } }<br />
public interface ILeft<X> { X Left { get; } }<br />
public interface IRight<X> { X Right { get; } }<br />
public interface ICreateRegion<X> { X CreateRegion(); }<br />
public interface ISplitVertical<X> { X SplitVertical(); }<br />
public interface ISplitHorizontal<X> { X SplitHorizontal(); }<br />
public interface IDone { void Done(); }<br />
Then, I defined a interface to join multiple interfaces together at each branch in the fluent interface:
<br />
public interface IBranch1<X> :<br />
ICreateRegion<X>,<br />
ISplitHorizontal<IBranch2<X>>,<br />
ISplitVertical<IBranch3<x>> { }<br />
<br />
public interface IBranch2<X> :<br />
ITop<IBranch1<IBottom<IBranch1<X>>>>, <br />
IBottom<IBranch1<ITop<IBranch1<X>>>> { }<br />
<br />
public interface IBranch3<x> :<br />
ILeft<IBranch1<IRight<IBranch1<X>>>>, <br />
IRight<IBranch1<ILeft<IBranch1<X>>>> { }<br />
</x>
Knowing that this was really ugly code, I decide to build a quick test:
<br />
public static class Foo<br />
{<br />
public static T FluentFactory<T><br />
{<br />
throw new NotImplementedException("Not yet implemented");<br />
}<br />
<br />
public static void Bar()<br />
{<br />
IBranch1<IDone> screen = FluentFactory<IBranch1<IDone>>();<br />
<br />
screen.Create().Done();<br />
<br />
screen.SplitHorizontal()<br />
.Top.Create()<br />
.Bottom.Create()<br />
.Done();<br />
<br />
screen.SplitVertical()<br />
.Left.Create()<br />
.Right.Create()<br />
.Done();<br />
<br />
screen.SplitVertical()<br />
.Left.SplitHorizontal()<br />
.Top.Create()<br />
.Bottom.Create()<br />
.Right.Create()<br />
.Done();<br />
}<br />
}<br />
<br />
static class Program<br />
{<br />
public delegate void Func();<br />
<br />
private static void TryAndCatch(Func x)<br />
{<br />
try<br />
{<br />
x.Invoke();<br />
}<br />
catch (NotImplementedException e)<br />
{<br />
MessageBox.Show(e.Message);<br />
}<br />
catch (TypeLoadException e)<br />
{<br />
MessageBox.Show(e.Message);<br />
}<br />
}<br />
<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
TryAndCatch(Foo.Bar);<br />
}<br />
And, sure enough, I got a TypeLoadException saying that I was using my generics recursively.
I changed the way the interfaces worked a bit, and arrived at this:
<br />
<br />
public interface ITop<X> { X Top { get; } }<br />
public interface IBottom<X> { X Bottom { get; } }<br />
public interface ILeft<X> { X Left { get; } }<br />
public interface IRight<X> { X Right { get; } }<br />
public interface ICreateRegion<X> { X CreateRegion(); }<br />
public interface ISplitVertical<X> { X SplitVertical(); }<br />
public interface ISplitHorizontal<X> { X SplitHorizontal(); }<br />
public interface IDone { void Done(); }<br />
<br />
public interface IBranch1<X> :<br />
ICreateRegion<X>,<br />
ISplitHorizontal<IBranch2<X>>,<br />
ISplitVertical<IBranch3<x>> { }<br />
<br />
public interface IBranch2<X><br />
{<br />
IBranch1<IBottom<IBranch1<X>>> Top { get; }<br />
IBranch1<ITop<IBranch1<X>>> Bottom { get; }<br />
}<br />
<br />
public interface IBranch3<x><br />
{<br />
IBranch1<IRight<IBranch1<X>>> Left { get; }<br />
IBranch1<ILeft<IBranch1<X>>> Right { get; }<br />
}<br />
</x>
Now, the TypeLoadException goes away and I simply get my (expected) NotImplemented exception.
My question is -- what is different about the first and second approach?
modified on Thursday, March 20, 2008 2:23 PM
|
|
|
|
|
I have a class declared as below.
<br />
class Error_codes<br />
{<br />
public string[] Error_category;<br />
public int[] Error_value;<br />
public string[] Error_comments;<br />
}<br />
I tried instantiating objects to the class by using the constructor as follows
<br />
Error_codes[] error_details = new Error_codes[70];<br />
<br />
TextReader sr = File.OpenText(ErrorCodes_FILE_NAME);<br />
{<br />
string input=null;<br />
int i = 0;<br />
while ((input=sr.ReadLine())!=null) <br />
{<br />
Regex regEx = new Regex("#(\\w*)");<br />
string[] tokens = regEx.Split(input);<br />
error_details[i]= tokens[2].ToString();<br />
error_details[i] = 20;
error_details[i] = tokens[4].ToString();<br />
i++;<br />
}<br />
sr.Close();<br />
}<br />
But I see an error "Cannot implicitly convert type 'string' to 'LoggingImprovements.Error_codes'". How do we instantiate constructors with errors?
|
|
|
|
|
error_details[i] is an object of type Error_codes
so when you use error_details[i]= tokens[2].ToString(); you are indeed trying to assign a string to and object of type Error_codes, i assume this lives in the LoggingImprovements namespace.
are you trying to do this?
error_details[i].Error_category = tokens[2].ToString();
in which case you would want your error_codes class to look like this:
class Error_codes<br />
{<br />
public string Error_category;<br />
public int Error_value;<br />
public string Error_comments;<br />
}
Hope this helps
|
|
|
|
|
Thanks Russel. I understood my error.
|
|
|
|
|
Hello friends
can anyone let me know how to send email through C#
if possible do let me knowplz
|
|
|
|
|
|
And don't cross post.
led mike
|
|
|
|
|
Hi everyone,
I am hoping to create an application in C# that will display a crystal report using a database that is defined at runtime. I've been doing some searching and I'm not sure if it's even possible. I know what fields I want the report to display, but I want to be able to specify, for example, an excel file and the specific columns to get the data from at runtime. Does anyone have advice for accomplishing this, or maybe other reporting tools that would be better suited?
Thanks
Tammy
|
|
|
|
|
It's possible and a headache...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
|
Ravi Mahavrathayajula wrote: string[0][max] tokens = regEx.Split(input);
The above is wrong, usually you don't know in advance how many items Split will return.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
|
What about:
List<string[]> myList = new List<string[]>();
string [] s;
Regex rgx= new Regex(";");
s = rgx.Split("A;B;C");
myList.Add(s);
s = rgx.Split("D;E;F;G;H");
myList.Add(s);
</string[]></string[]>
?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Omit needless local variables.
myList.Add(rgx.Split("D;E;F;G;H"));
|
|
|
|
|
Maybe (expecially if you don't need debugging), anyway it's a matter of taste.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
What's more annoying than people who delete their posts after they are answered ?
I'm not sure either....
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
There shouldn't be a way to delete a post.
|
|
|
|
|
PIEBALDconsult wrote: There shouldn't be a way to delete a post
I agree. Once there has been a reply, the delete link should just disappear..
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Is there any tool or way to compare performance of two statements.
What I generally do is put it in loop and use Timespan to find out the difference.
Is there any better way of doing it? or are there any standard tools available for this?
Keep DotNetting!!
GeekFromIndia
|
|
|
|
|
Yep, you can use a profiler. I use Ants[^], which works for me (it's not free, but there's a trial available).
Standards are great! Everybody should have one!
|
|
|
|
|
$295
thats a costly affair...i would prefer sticking to my looping way...
but thanks for info...i'll try finding if there are any profilers available for less price..
Keep DotNetting!!
GeekFromIndia
|
|
|
|
|
|
I don't think that's that expensive when compared to the amount of time it saves on debugging performance issues. Anyway: The way things are with the dollar right now that's only 187 euros for me .
Standards are great! Everybody should have one!
|
|
|
|