|
Thanks a lot. Incredible I've never came across these functions, since I'Ve been searching for registry, key, ... the whole day through MSDN.
~RaGE();
|
|
|
|
|
Well, actually, i cannot open this key.
here's my code : what's wrong ?
PHKEY kHandle=new HKEY;
LPCTSTR Key="Control Panel\\International";
LPTSTR b;
PLONG d;
long int yop=RegOpenKeyEx(HKEY_CURRENT_USER,Key,0,KEY_QUERY_VALUE,kHandle);
if (yop==ERROR_SUCCESS)
{
RegQueryValue(*kHandle,"sDecimal",b,d);
}
yop comes up with 998.
Could you provide me with an example ? The key was
HKEY_CURRENT_USER\Control Panel\International\sDecimal
Thank you very much
~RaGE();
|
|
|
|
|
hi,
this is done like this..I think you are doing right..
except.. in last argument pass address of kHandle..like this and use it like..
RegOpenKeyEx(HKEY_CURRENT_USER, _T("software"), 0, KEY_WRITE|KEY_READ,
&kHandle);
I hope this time it works..
cheers
Himanshu
|
|
|
|
|
|
I'm here again asking for advice for my server that I'm developing.
I'm using blocking sockets and of course it's multithreaded.
I put all my accepted clients in a std::list object and when a client send a message to all clients (or just one), should I always check the list if there is any disconnected clients and then remove them from the list before I send the messages to all clients in the list?
Should I have a timer or something that updating the list every n seconds or would that slow down the system?
Short say: How often or when should I update my std::list ?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I highly recommend that you redesign the server using a robust non-blocking I/O such as Overlapped I/O and Completion Port I/O. Under non-blocking I/O, the OS will notify the server the state of the sockets.
In terms of solution for this problem, there is no elegant solution. One solution is to process all sockets and determine their states. The time interval depends on the type of server.
Kuphryn
|
|
|
|
|
kuphryn wrote:
non-blocking I/O
I don't understand non-blocking sockets but I want to.
There is one problem, I have no idea where to read about non-blocking sockets!
So if you could give me a name of a good book or a link to a good and big tutorial, would that be nice!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
There are several articles on overlapped I/O and I/O completion ports on CP. Look in the internet and networks section. Non blocking sockets, while good, will not tell you whether a client is connected or not (unless you do something else to your code, but then you could do something similar to your existing code too).
Overlapped I/O is simple really. Instead of thinking in terms of threads, clients or sockets, you need to think in terms of events (read, write, send, recieve, etc). Once you get the hang of it, you will find it is more appropriate in many situations. On the other hand, just because non blocking sockets exist, does not mean you should use them in every situation. It takes much longer to implement them, and the gain is not always worth it. Only if your server is always busy, will you see an advantage.
In the mean time, while you are reading up on non blocking sockets, you could try this:
Keep a timer for all your sockets. Every receive resets the timer. If the timer is fired, a function will check to see if the client is disconnected. If it is, the client will be removed from the list. If not, the timer will be reset.
This will only be advisable if there aren't too many clients at the same time. Otherwise a lot of resources might be used up just for the timers. If there are too many clients connected, you may consider overlapped I/O.
Regards,
Rohit Sinha
|
|
|
|
|
Hey Rickard, I do it similar in my chat:
If a client socket gets a disconnect event, it shuts down and then marks itself as dead. One regular server timer will check for dead sockets (in a std::vector or std::list) and remove them from the list. I dont like if objects delete themself on their own, which is possible in C++ of course (but you have to do some locking etc to be thread safe).
A regular timer sounds like a waste... but it doesnt eat much time and for my chat I already needed regular checks, for things like: is client timeout, is client flooding, client needs a welcome etc. ATM I do this checks every second.
So, when the server becomes a message "Rickard greets all" for sending to all clients, it goes through the list and sends it to every client that is not dead (and properly logged in). All dead sockets become removed in regular intervalls and won't polute the socket list for long. You might want to maintain more then one internal list, e.g. one for 'incoming and not logged in crap sockets' and one for 'logged in chat client sockets'.
Hope it helps... hej då, Moak
|
|
|
|
|
Moak wrote:
So, when the server becomes a message "Rickard greets all" for sending to all clients, it goes through the list and sends it to every client that is not dead (and properly logged in). All dead sockets become removed in regular intervalls and won't polute the socket list for long.
Okay, let's say you do start sending to all clients in the list and then suddenly a socket gets closed , the regular interval will delete it after sending because it suddenly became dead (if you know what I mean, perhaps not), that means I will do a send() call to a dead socket. Is that bad? I mean it shouldn't be... doesn't it just return an error code or something if I send to a dead socket?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Rickard Andersson wrote:
start sending to all clients in the list and then suddenly a socket gets closed
Well... that is strictly NOT allowed to happen (but it will of course). What you do to prevent such cases does hardly depend on your socket concept.
If you run a nonblocking multi threaded server concept you need to hazzle with locking on your own. E.g. wait in client thread until server thread signs "okay, socket list is available for write attempts" (beware of deadlocks). I mean, two threads writing simultanously on a STL container is a 'no no'. Just sending to an unconnected/dead socket will cause IMHO an uncritical error return value (which you can ignore).
If you have a nonblocking asychronous concept within one thread context you're lucky as it is. Because all client/server events are allready "synchronized" and come one after another. I do it this way in my chat. Regarding your question: in this socket concept one socket event says "receiving data" and you decide to send your stuff to all clients.... the next socket event says "socket disconnected" and you mark socket as dead for later remove. That's it here.
Hope it helps a bit, Moak
|
|
|
|
|
Moak wrote:
If you run a nonblocking multi threaded server concept you need to hazzle with locking on your own. E.g. wait in client thread until server thread signs "okay, socket list is available for write attempts" (beware of deadlocks). I mean, two threads writing simultanously on a STL container is a 'no no'. Just sending to an unconnected/dead socket will cause IMHO an uncritical error return value (which you can ignore).
My first design was almost like this except from my design was with blocking sockets.
But now I trying to use that one you mention below...
Moak wrote:
If you have a nonblocking asychronous concept within one thread context you're lucky as it is. Because all client/server events are allready "synchronized" and come one after another.
Yes, I use that concept for now. It's much more powerful and STABLE than the blocking multi threaded concept!
Moak wrote:
the next socket event says "socket disconnected" and you mark socket as dead for later remove.
Aaah! My regular interval removes it from the list, I just mark it dead!! woohoo!!
Thank you so so much!
You've teached me more than anybody has! I mean it, you're really know this topic!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Rickard Andersson wrote:
You've teached me more than anybody has! I mean it, you're really know this topic!
Ah cool, it works and I could help!! prolly I know some stuff b/c I program a chat as well and so do run into same questions. Just ask if there is more...
Greets, Moak
PS: Oh and please don't make your chat better than mine! *kidding*
|
|
|
|
|
Moak wrote:
PS: Oh and please don't make your chat better than mine!
Mowahaha!
I will make a better chat than anyone! A better than ICQ and MSN!!!! Better then ALL chat systems in the whole world!!!
Rickard, stop dreaming....
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Hey Moak, can you explain how FD_WRITE works!?
I do like this:
case WM_SOCKET:
if (WSAGETSELECTERROR(lParam))
{
closesocket(wParam);
break;
}
switch(WSAGETSELECTEVENT(lParam))
{
case FD_ACCEPT:
Accept = accept(wParam, NULL, NULL);
WSAAsyncSelect(Accept, hWnd, WM_SOCKET,
FD_READ | FD_WRITE | FD_CLOSE);
break;
case FD_READ:
MessageBox(NULL, "FD_READ", "FD_READ",MB_OK);
break;
case FD_WRITE:
MessageBox(NULL, "FD_WRITE", "FD_WRITE",MB_OK);
break;
case FD_CLOSE:
MessageBox(NULL, "FD_CLOSE", "CLOSE",MB_OK);
closesocket(wParam);
break;
}
break;
What I have problems with is that I don't really understand the use of FD_WRITE.
When does my WndProc get this message???
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Rickard Andersson wrote:
What I have problems with is that I don't really understand the use of FD_WRITE.
Hm... when you are allowed to send more data (ATM you don't need to handle with it since you do not send large amount of data).
Doesn't answer your question, right? Well, it's a FAQ so I'm lazy and suggest to read some winsock references. See link in last posts or e.g. here http://www.hal-pc.org/~johnnie2/winsock.html[^]
[EDIT]PS: Have a look into Sockcore.cpp if you want to stick with Winsock's asynchronous mode[/EDIT]
|
|
|
|
|
Moak wrote:
Hm... when you are allowed to send more data
You mean if I send a buffert that is 200 bytes large but I only send 100 bytes at time.. then the FD_WRITE is sent?
Hm.. but wait... I can't send 100 byte and let the socket know there is more data to send? Or?
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Rickard Andersson wrote:
You mean if I send a buffert that is 200 bytes large but I only send 100 bytes at time
AFAIK when the internal socket buffer of your TCP/IP stack is full AND then becomes empty/writeable again. But I'm not a Windows sockets specialist, I bet there's a Winsock FAQ.
I suggest reading more about TCP's streaming nature (e.g. data packages, Nagle algorithm and never forget to collect packages). I think it's a interesting topic and internet programmers should know what happens. First of all it's very intersting (I repeat myself), secondly only a deeper understanding makes efficient network programming possible. (I wish, I knew more about encryption coding like SSL or ipsec).
Cya Moak
|
|
|
|
|
I highly recommend Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund.
Kuphryn
|
|
|
|
|
Also Win32 Network Programming is one of the best books (written by Ralph Davis, ISBN=0-201-48930-9).
A. Riazi
|
|
|
|
|
howdy, i'm looking to start out with some internet work, i've read some articles here about winsock etc. I was just wondering which you would suggest to use, wininet or winsock? What the differences are? Maybe a nice refernce to somewhere where I can get this info. is there any other libs to use? etc.
thanks for any info.
Luke.
|
|
|
|
|
From MSDN Library:
How WinInet Makes It Easier to Create Internet Client Applications
The Win32 Internet Extensions, or WinInet, provide access to common Internet protocols, including gopher, FTP, and HTTP. Using WinInet, you can write Internet client applications at a higher level of programming, without having to deal with WinSock, TCP/IP, or the details of specific Internet protocols. WinInet provides a consistent set of functions for all three protocols, with a familiar Win32 API interface. This consistency minimizes code changes you need to make if the underlying protocol changes (for example, from FTP to HTTP).
Visual C++ provides two ways for you to use WinInet. You can call the Win32 Internet functions directly (see the OLE documentation in the Platform SDK for more information) or you can use WinInet through the MFC WinInet classes.
You can use WinInet to:
Download HTML pages.
HTTP is a protocol used to transfer HTML pages from a server to a client browser.
Send FTP requests to upload or download files or get directory listings.
A typical request is an anonymous logon to download a file.
Use gopher's menu system for accessing resources on the Internet.
Menu items can be several types, including other menus, an indexed database you can search, a newsgroup, or a file.
For all three protocols, you establish a connection, make requests to the server, and close the connection.
The MFC WinInet classes make it easy to:
Read information from HTTP, FTP, and gopher servers as easily as reading files from a hard drive.
Use HTTP, FTP, and gopher protocols without programming directly to WinSock or TCP/IP.
Developers who use the Win32 Internet functions do not need to be familiar with TCP/IP or Windows Sockets. You can still program at the socket level, using WinSock and TCP/IP protocols directly, but it's even easier to use the MFC WinInet classes to access HTTP, FTP, and gopher protocols across the Internet. For many common operations, developers do not need to know the details of the particular protocol they are using.
Many operations that can be performed by your computer as a client to other computers on the Internet can take a long time. The speed of these operations is usually limited by the speed of your network connection, but they can also be affected by other network traffic and the complexity of the operation. Connecting to a remote FTP server, for example, requires that your computer first look up the name of that server to find its address. Your application will then attempt to connect to the server at that address. Once the connection is opened, your computer and the remote server will initiate a conversation with the file transfer protocol before you can actually use the connection to retrieve files.
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
thanks for that, and I must say sorry. Not long after I posted that I found similar information. So thanks anyhow..
now off to read about winsock
bye
Luke.
|
|
|
|
|
How to encrypt / Decrypt using RSA algorithm.
I need to get the public key and private key in two different files.
Can anyone help me please
|
|
|
|
|
|