G
Guest
Hi,
I have a class library that I reference in my project. The class library is
a wrapper for the UDP client class. Now when data comes in on a socket, it
notifies my application and I can then retrieve that data. The problem is how
to handle events that might happen at the same time. If you bear with me I
can outline it with some code as follows.
In my application, I have an array of objects that are instances of this
class library.
e.g.
MyClassLib.Sock[] MySock = new MyClassLib.Sock[3]
I instantiate each object as follows::
int intPortToBind = 5600;
for(int intLoopCounter = 0; intLoopCounter < 3; intLoopCounter++)
{
MySock[intLoopCounter] = new MyClassLib.Sock();
MySock[intLoopCounter].Bind(intPortToBind);
MySock[intLoopCounter].Event1 += new
MyClassLib.Sock.Event1Handler(MySock_Event1);
intPortToBind++;
}
And finally my event handler looks like the following::
private void MySock_Event1(string sData, string sRemoteHost, int nRemotePort)
{
tbReceive.Text = tbReceive.Text + sData ;
}
Now I can communicate with peers fine, as long as it is one at a time.
However if I try sending some data to "localhost" through a UDP connection, I
get back data only from one object not all three. I even step through the
debugger, and my event handler fires all the time, and I get valid data from
all three objects, but the text box only has data from one of the objects.
Here's how my send code looks like::
int intPortToBind = 5600;
for(int intLoopCounter = 0; intLoopCounter < 3; intLoopCounter++)
{
MySock[intLoopCounter].Send(intLoopCounter.ToString(), "localhost",
intPortToBind);
intPortToBind++;
}
Theoretically the output text box should have 012, but it sometimes has 1,
or sometimes has 2 etc.
Does it have something to do with the fact that data is coming on all 3
sockets at the same time. If so shouldn't it all be queued up in buffers
associated with all three sockets? Can someone suggest a workaround this, if
they have to run into something similar?
Thanks in advance,
Pete.
I have a class library that I reference in my project. The class library is
a wrapper for the UDP client class. Now when data comes in on a socket, it
notifies my application and I can then retrieve that data. The problem is how
to handle events that might happen at the same time. If you bear with me I
can outline it with some code as follows.
In my application, I have an array of objects that are instances of this
class library.
e.g.
MyClassLib.Sock[] MySock = new MyClassLib.Sock[3]
I instantiate each object as follows::
int intPortToBind = 5600;
for(int intLoopCounter = 0; intLoopCounter < 3; intLoopCounter++)
{
MySock[intLoopCounter] = new MyClassLib.Sock();
MySock[intLoopCounter].Bind(intPortToBind);
MySock[intLoopCounter].Event1 += new
MyClassLib.Sock.Event1Handler(MySock_Event1);
intPortToBind++;
}
And finally my event handler looks like the following::
private void MySock_Event1(string sData, string sRemoteHost, int nRemotePort)
{
tbReceive.Text = tbReceive.Text + sData ;
}
Now I can communicate with peers fine, as long as it is one at a time.
However if I try sending some data to "localhost" through a UDP connection, I
get back data only from one object not all three. I even step through the
debugger, and my event handler fires all the time, and I get valid data from
all three objects, but the text box only has data from one of the objects.
Here's how my send code looks like::
int intPortToBind = 5600;
for(int intLoopCounter = 0; intLoopCounter < 3; intLoopCounter++)
{
MySock[intLoopCounter].Send(intLoopCounter.ToString(), "localhost",
intPortToBind);
intPortToBind++;
}
Theoretically the output text box should have 012, but it sometimes has 1,
or sometimes has 2 etc.
Does it have something to do with the fact that data is coming on all 3
sockets at the same time. If so shouldn't it all be queued up in buffers
associated with all three sockets? Can someone suggest a workaround this, if
they have to run into something similar?
Thanks in advance,
Pete.