|
I took out the memset and did the straight char, yes it works and it's faster,
OK, feel stupid but I did not fully understand the process. I tried it earlier, but got some kind of Int error.
Do you know anything about the receive side of the socket? it just sits there and never closes, or transfer data to the receive buffer.
|
|
|
|
|
I don't remember exactly off hand what it should do... but since UDP is essentially connectionless (meaning no hand-shaking between server and client), I imagine the socket has to be closed explicitly by the application.
jkirkerx wrote: or transfer data to the receive buffer.
Don't know exactly what you mean by that.
|
|
|
|
|
I took a generic winsock2 sample code and modified it for UDP broadcast. I have come to the same conclusion, in which the socket will never close, because it's not an single machine to machine connection, in which the other side will never send the symbol saying it's done, or simply close it's port.
I just need to figure out how to capture the return data.
Not sure if I need 2 sockets, one to just send the broadcast, and the other to just listen. If I do that, I'm afraid the listening socket will cause my code to stop, and I won't be able do anything until the socket closes.
|
|
|
|
|
Finally figured it out, and got back packets from all the SQL Servers on the network, complete with all the information I need.
So now I know how to send a STX command to SQL Browser, to start a conversation. It's sort of like a modem command.
Now I have to figure out how and when to release the receive side of the socket, and only capture the packets that I need.
So the SendMessage, which is a char string, has to be set with memset, in order to send just the byte.
|
|
|
|
|
A char* is not necessarily a string... it's just a char pointer... in network programming, character buffers are commonly used to hold the data being transferred to/from a socket because of the size of a char is one byte. It's just convenient to use that since it's the smallest data element used/transferred.
|
|
|
|
|
To make my code more readable I'm trying to use a set of defined values in a switch statement. Basically I have a 4 CHAR tag I want to convert to a DWORD.
#define _makeTag(x) ((#x[0] << 24) | (#x[1] << 16) | (#x[2] << 8) | #x[3])
#define tag_cmap _makeTag(cmap)
In the above I have a 4 CHAR string "cmap" which in DWORD form should be 0x636d6170. However when using in a switch statement the compiler complains that it's not constant. The commented line works, however I believe it to be unreadable.
Any suggestions?
My previous method was to use a union but that required a loop over all the values, hence slow code.
Waldermort
|
|
|
|
|
no, it's not const. Because it's not a compile-time operation. You're accessing a memory location. If you were to look at the generated C-code, it would look like the following:
(("cmap"[0] << 24) | ("cmap"[1] << 16) | ("cmap"[2] << 8) | ("cmap"[3]))
So, it's runtime code, *not* a constant.
You could try assigning it to a constant though, as follows:
const tag_cmap = _makeTag(cmap);
instead of the
#define tag_cmap
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
ahmed zahmed wrote: You're accessing a memory location.
LOL, That thought hit me right after posting the message.
Compiler still complains when assigning to a const.
I've decided to go with my first method but instead to use _makeTag('c','m','a','p') directly in the switch.
Thanks again.
Waldermort
|
|
|
|
|
It turns out that you do not need a macro at all to do what you want.
Try this -
DWORD d = 'cmap';
Please note the single quotation marks.
|
|
|
|
|
Nice!
Out of curiosity what compiler are you using? I think I may have tried that back on VS8 but with errors.
Waldermort
|
|
|
|
|
I currently use VS2010, but I'm sure this works in older compilers, because this type of assignment is used to tag memory allocations in kernel mode code from ages ago.
|
|
|
|
|
WalderMort wrote: Any suggestions?
Why, yes: don't use macros, they make your code unreadable
No, seriously: using macros is dangerous, with very few exceptions. Regarding your example, your choice of symbol alone already breaks two common safeguards against macro problems:
1. Do not ever use a symbol with starting '_'! This is what the system libraries use internaly to prevent name clashes with any symbols the programmer may define! The problem with name clashes and macros is that macros clash silently, and may break system libraries, resulting in very hard to trace runtime errors (or compiler error,s, if you're lucky)
2. Use capital letters for symbols denoting const or #define symbols. This, also, has to do with preventing name clashes. It may seem overkill, but better be safe than sorry.
I've spent many, many weeks hunting down errors caused my macro name clashes caused by other people's code (and in some cases even by MS #defines!). Do yourself (and everyone else) a favor and don't add to that misery!
|
|
|
|
|
Hi all,
I am trying to play video files in my application. i have used MCIWndCreate function but i am having a problem.
I want to display video on my screen of a particular size, for aciheving this i have created a static control and passed its handle to MCIWndCreate. Video is displayed of its size only but it is cuting from sides i.e its not showing full video.
i have written this line of code
HWND h = m_static1.GetSafeHwnd();
m_Player = MCIWndCreate(h,AfxGetInstanceHandle(),
WS_CHILD | WS_VISIBLE|MCIWNDF_NOPLAYBAR, _T("D:\\2.mpeg"));
How can i do this??
Thanks in advance
|
|
|
|
|
I see from the docs [^]that you've also got the two flags MCIWNDF_NOAUTOSIZEWINDOW and MCIWNDF_NOAUTOSIZEMOVIE - one for preventing the window being sized to fit the movie, the other for preventing the movie being resized to fit the window.
I'd be inclined to try adding the first flag. (never used any of these functions)
|
|
|
|
|
Hello!
I've got a problem with a CHtmlView derived View on Windows 7.
The CHtmlView derived View is embedded in a CTabView with the following code:
int COSTabbedView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTabView::OnCreate(lpCreateStruct) == -1)
return -1;
AddView (RUNTIME_CLASS (CResultView), _T("Results"), 100);
AddView (RUNTIME_CLASS (CBrowserView), _T("Certificate"), 101);
return 0;
}
The view itself is initialized by:
void CBrowserView::OnInitialUpdate()
{
CHtmlView::OnInitialUpdate();
Navigate2(_T("http://www.google.de"));
}
On a Windows XP machine this works fine. The view displays the requested page.
On Windows 7 the status bar of my application says something like "Downloading from www.google.de" and then a new Internet Explorer window will open and display the site but not with "www.google.de" in the address bar, but the path of the temporary downloaded file (!?).
I've been searching around for several days now and found out at least one interesting thing:
When I use Spy++ on WinXP I see the following windows below my view window:
Shell Embedding
+ Shell DocObject View
+ Internet Explorer_Server
On Windows 7 the "Shell DocObject View" and the "Internet Explorer_Server" window are missing.
So I debugged into the creation of the CHtmlView window but they both behave the same on Win7 and XP.
Does anyone have a hint what is going wrong here?
|
|
|
|
|
I need to implement TCP hole punching in my application. I tried to google to find any sample implementation but could not get.
Please suggest me idea behind TCP hole punhing with example...
|
|
|
|
|
|
UDP/TCP hole punching is Communication between two computers without opening ports,
using a third computer to set up the connection
UDP/TCP hole punching is NOT a security violation in any way, even though the name suggests it is.
Once the hole has been punched in the firewall, only connections from the specified client
are accepted through it, it isn't like anyone can get in through the hole.
Get the win32 DLL here:
http://www.cis.nctu.edu.tw/~gis87577/xDreaming/XSTUNT/index.html[^]
It works like this:
A--->proxy --------proxy<---B
|
S
Let A be the client requesting the connection
Let B be the client that is responding to the request
Let S be the server that they contact to initiate the connection
A sends a connection request to S
S responds with B's IP and port info, and sends A's IP and port info to B
A sends a UDP/TCP packet to B, which B's router firewall drops but it still punches a hole in A's own firewall where B can connect
B sends a UDP/TCP packet to A, that both punches a hole in their own firewall, and reaches A through the hole that they punched in their own firewall
A and B can now communicate through their established connection without the help of S
All this does is make both A and B's firewalls think that they have initiated the connection,
just as it would let packets from a web server through ONLY if the client had initiated the connection
to the web server and the packets were expected.
This is not a security risk and software that uses this method should not be looked down upon,
this is how p2p software like AIM and most VoIP clients initiate connections.
TCP hole punching Algorithm
Let A and B be the two hosts, each in its own private network;
N1 and N2 are the two NAT devices;
S is a public server with a well-known globally reachable IP address.
A and B each begin a TCP conversation with S;
the NAT devices N1 and N2 create TCP translation states and assign temporary external port numbers
S relays these port numbers back to A and B
A and B contact each others' NAT devices directly on the translated ports;
the NAT devices use the previously created translation states and send the packets to A and B
The Low TTL is calculated as follow:
Send SYN with TTL of i=1
Wait for ICMP TTL Exceeded message
i = i + 1, loop
Loop until "ICMP TTL Exceeded" messages are no longer received.
The own NAT host has been traversed.
The LOW TTL Value = i + 1.
If the NAT host supports "ICMP TTL Exceeded" messages to internal hosts, then the RST reply from buddy can be inspected.
The LOW TTL Value = i - 1.
http://en.wikipedia.org/wiki/TCP_hole_punching
http://nutss.gforge.cis.cornell.edu/stunt.php
http://en.wikipedia.org/wiki/STUN
|
|
|
|
|
|
|
Pretty sure it can be more complicated than the other replies suggest.
Presuming a physical connection between two computers exists then the control of that channel will certainly fall under one or more routers and possibly one or more firewalls.
If any one of those precludes communication then the linkage will fail.
So one must know that all of them exist and be prepared to configure all of them.
|
|
|
|
|
I've created a custom control, using the low level win32 api, which displays an animation. Using a thread I render a frame, or rather update the parts need it, and call InvalidateRect passing the area that was changed. In the main thread I handle WM_PAINT with the BeginPaint EndPaint pair AND use the paintstruct's rect to repaint only the area required.
The rendering is backed by a TimerQueue, an event and a thread that waits on the event.
I couldn't work out why my CPU usage was hovering around 80%. Each frame involves a lot of alpha blending hence the need to only update the changed parts.
After 2 days I've narrowed the problem to BeginPaint. MSDN states, and this is GDI 101, when handling a WM_PAINT message BeginPaint and EndPaint should be called to validate the invalid rect, otherwise windows will continue to post the message.
Well, it's just not happening. The window has not been validated and my code has been rendering the full client area (lot's of work) on each call. If I add a ValidateRect in my handler the problem goes away and CPU down to 0-1%.
My question is why? Is this a bug or am I missing something?
Waldermort
|
|
|
|
|
WalderMort wrote: a ValidateRect in my handler the problem goes away I think that's the correct way.
Don't know if it's a bug or not.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
|
Hmpf! I stand corrected. I was going off of faint memory. Like I said, "I thought".
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|