|
I have multiple processes on the same machine listening for datagrams on the same UDP port.
I'm setting up each socket to reuse the address like this:
BOOL bTrue = TRUE ;
if ( setsockopt(hSocket , SOL_SOCKET , SO_REUSEADDR , (char *)&bTrue , sizeof(bTrue) ) != 0 )
and the bind() is working fine as well:
struct sockaddr_in sockAddr ;
sockAddr.sin_family = AF_INET ;
sockAddr.sin_addr.s_addr = inet_addr( "127.0.0.1" ) ;
sockAddr.sin_port = htons( 1001 ) ;
if ( bind( hSocket , (sockaddr*)&sockAddr , sizeof(sockAddr)) != 0 )
But when I broadcast a message, only one process gets it (the first one to open the socket). Is this a limitation of UDP or have I missed something?
Software is everything. It also sucks. Charles Fishman [^]
Awasu 1.0.4 (beta)[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Taka Muraoka wrote:
Is this a limitation of UDP or have I missed something?
There are 3 uses of SO_REUSEADDR:
1. Allows a server to listen on an address/port that already has an established connection on it, ie. TCP only.
2. Allows multiple binds on the same port, as long as they use different IP addresses. This works with either multiple processes or one process.
3. Allows completely duplicate binding (same IP address and port), but only if the sockets implementation supports multicasting.
Your situation is the third case. Unfortunately, the Windows Sockets IPv4 implementation does not support multicasting, so the bind will work, but only the first socket to do the bind will receive any datagrams.
In any case, IPv4 only supports multicasting addresses that are from 224.0.0.0 to 239.255.255.255
Hope this helps
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Bugger. I'm working around it now anyway - it's pretty ugly but wtf...
Thanks for the help.
Software is everything. It also sucks. Charles Fishman [^]
Awasu 1.0.4 (beta)[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
How can i search for characters like " and \ in an edit control?
-- Steve
|
|
|
|
|
First read the text from the edit control.
CString strMyString;
GetDlgItem( IDC_MYEDIT )->GetWindowText( strMyString );
// Search for "
int nIndex1 = strMyString.Find( '"' );
// Search for \
int nIndex2 = strMyString.Find( '\\' );
If you have more than one occurences of each of these characters, use int CString::Find( TCHAR somechar, int nStart )
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
|
Dear everyone,
i meet one problem.
Our application need the following function:
when user change the window size, the controls in the window need resizing, and the font in the controls need be modified, too.
I think it is some difficult and complicated, could you tell me how to implement and where could find the article or resource about it?
Welcome any suggestion!
Good Luck
|
|
|
|
|
Handle the WM_SIZE message in the parent, and call the MoveWindow() or SetWindowPos() functions for all the children.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
There are lots of code here in CP regarding on this, I've been using for a long time the ControlPos class that it's very easy to use...
Hope this helps...
|
|
|
|
|
when we transfer one polymorphic object from one side of the network to other side of the network computer then we
unmarshal the objects string into it polymorphic object.
then how super class knows that
where and what is its sub class object stored in super class pointer out of many subclass objects?
r00d0034@yahoo.com
|
|
|
|
|
I am working on a program where I keep background textures in a separate DLL (for simple upgrade possibilities).
I use LoadBitmap in the DLL and I export the pointer to the asociated CBitmap to the application.
Everything works fine, except that refresh is quite slow now.
Does anyone know/recognize this behaviour , or did I do something else wrong?
If someone has a clue and solution, please let me know.
Bert....
|
|
|
|
|
Hi,
I created a splitter for SDI with two views and one document, left view just for the snapshot of my main (right) view.
My question is, haw to do my main view (right frame) always active even if I click on the left frame???
Thank you.
|
|
|
|
|
In your left view, override OnActivateView() and call the splitter function SetActivePane(0,1)
|
|
|
|
|
Hey guys
I am using MFC -> File Open dialog box, which works fine.
I have noticed other applications use a different style of dialog box wich has quick buttons on the left that brings the navigation tree in the open dialog box to those locations.
For example in Microsft Word, when you go File -> Open, there are 5 buttons on the left (History, My Documents, Desktop, Favorites, My Network places)
I would also like the same type of "File Open" dialog box. How do I impliment this. I have searched the MSDN documentation and have come up with nothing.
Any help appreciated
George W
Software Developer
www.zsystems.ca
|
|
|
|
|
It's called the "Places" bar, and comes with a new version of commdlg.dll. So instead of using CFileDialog, you'll have to use GetOpenFileName(). If the OPENFILENAME structure uses a hook procedure (or the OFN_ENABLETEMPLATE is set), you will get the old-style dialog; otherwise, you will get the one with the "Places" bar. This explains why MFC apps get the old dialog—because CFileDialog, like all MFC common dialogs, uses a hook procedure. Search MSDN, or the Web, for details.
|
|
|
|
|
Thanks for help
I will look into this.
George W
Software Developer
www.zsystems.ca
|
|
|
|
|
Suppose I have a class with a few member variables, and one of them is a CArray object, e.g.:
CMyClass {
...
private:
int var1, var2, var3;
bool flag1, flag2, flag3;
CArray <int,int&> arSomeArray;
};
If I didn't have that CArray member, I could simply write:
CMyClass a, b;
a = b;
The assignment operator would be simply generated by compiler. But when CArray is there, compiler cannot generate default assigment operator, so I have to add to the class:
CMyClass& operator= (CMyClass& src){
var1 = src.var1;
var2 = src.var2;
var3 = src.var3;
flag1 = src.flag1;
flag2 = src.flag2;
flag3 = src.flag3;
arSomArray.Copy (src.arSomeArray);
return *this;
}
Not only that it is very tedious writing a few dozen of "x = src.x ", it is also prone to bugs. Like later I will add a variable to the class and might forget to add it to the operator= function.
Is there a way to write something like below?
CMyClass& operator= (CMyClass& src){
dear_compiler_do_what_you_can_with_all_the_variables_i_ll_take_care_of_the_rest();
arSomArray.Copy (src.arSomeArray);
return *this;
}
Thanks
|
|
|
|
|
Not using CArray would be a good start MFC's container classes suck. Try using a stl container instead, it might just change your life.
Ryan
|
|
|
|
|
I agree 100%. I've used the MFC containers for years but STL is much more powerful and more portable. I wish I switched a long time ago. Try std::vector
John
|
|
|
|
|
Thanks, but I am not going to rewrite a few hundred of classes, possibly breaking several projects along the way, just for this cause.
Having CArray with all its upsides and downsides is a must.
|
|
|
|
|
I know what you mean. I have a lot of code in several DLLs that sill has MFC containers and in most cases it is better not to rewrite but I wish I would have known stl in the first place. Anything new I will use stl containers instead of MFC.
John
|
|
|
|
|
You could declare all the members you want automatically copied in a structure defined within the class - C++ will then generate an assignment operator for that structure.
e.g.
class Blah
{
private:
struct Hidden
{
int a;
int b;
};
Hidden h;
CArray<int,int> array;
Blah& operator=(const Blah& copy)
{
h = copy.h;
// Copy the array...
}
};
However, as others have pointed out, if you use STL you don't run into these problems.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
The idea is good, however separating some variables into a structure just for coding convinience would not make sense to someoneelse reading the code.
|
|
|
|
|
|
What about writing a quick subclass of CArray that defines operator= and simply calls CArray::Copy()? That would still be compatible with your other class that just use CArray.
--Dean
|
|
|
|