Add your own alternative version
Stats
2M views 25.1K downloads 494 bookmarked
Posted
15 Aug 2000
|
Comments and Discussions
|
|
Well that's a problem.
But Sebastien how could the condition when one of the clients has error and it suddenly ended abnormally, that client can notify the server and Server will delete that client from the list? Why does vice-versa( Server notifies Client ) is not possible?
So how can all clients be able to know if the connection is not available? Do you have any other way of handling this condition? How does your game that has been working fine without any complaints handle this condition?
I think unexpected error occured is a common problem in the computer world, isn't it?
Thank you.
|
|
|
|
|
The server can send from time to time a ping to the client. He will knows when the client has an unexpected error. The same thing can be applied for the client (he can send message to the server).
|
|
|
|
|
Ok I see. Now I am thinking about your idea of how to make the client side also behave like server side.
I have tried to make all clients LISTENING to the server existence and according to my mind it should have worked but I've got one big problem:
When Server has error, it needs to be restarted, after that all clients need not to restart their applications because I have make them ALSO listening like the server does. But when came to this condition, I got both Server and Client WAITING each other to send a NOTIFICATION packet.
Problem on Server side: How can Server get all clients that it need to send them the NOTIFICATION packet since there HASN'T been any clients connecting since the Server app Restarted?
Problem on Client side: It is now Listening to check if the Server is exist or not. The problem is when can clients know if the Server has been ON / ACTIVE again if the Server have not been able to SEND NOTIFICATION packet to its clients?
How to solve this problems?
I have used CNDKServer::IsStarted(), CNDKServer::StartListening() andCNDKServer::Stop() and put them on the CNDKClient to make clients also LISTENING. Is this correct?
Thank you.
|
|
|
|
|
There is nothing that you need to modify in the NDK, it is only on your app side.
Unfortunately, I do not have the time to help you on this.
Sébastien
|
|
|
|
|
Sebastien, each time a Client dialog call the NDKClient::OpenConnection(), I tried to modify your OpenConnection() function because I need to connect to NOT a Single server but SEVERAL Servers. So I need to save all the CNDKClientSocket object to a CObList and I also remove CloseConnection() function call on the first part of OpenConnection and I move it to OnDestroy event of the application.
I do the CloseConnection() by looping the CObList data and close the CNDKClient one by one per socket object.
Problems: I cannot save the CNDKClientSocket object pointer because it always points to invalid address and of course a Runtime error occured stating that the archiveOut object points to an invalid address, I wonder how could this happen, I have saved the pointer as soon after it is created and DID NOT call any CloseConnection or CleanUp, how could this happen?
And also I am experiencing a little problem with destroying the CNDKClientSocket objects I have saved in a CObList. Sometimes it cause the app to be hung.
It is actually possible to do what I need, isn't it?
How to solve this?
Thank you very much.
modified on Thursday, December 25, 2008 1:02 AM
|
|
|
|
|
I have a project that uses the Server portion as a Service on one of the computers to redistribute messages to all connected clients. It works great except if any of the computers sit idle for 30 minutes to an hour, they do not receive any messages sent by other computers. The "sleeping" computer can still send with no problem, so it appears to still be connected, it just doesn't receive. Any suggestions?
|
|
|
|
|
Hey i tried to compile everything in visual studio 2005. The dll gets copiled well but the server and the client brings an error:
Error 1 error LNK2019: unresolved external symbol "public: virtual __thiscall CNDKClient::~CNDKClient(void)" (??1CNDKClient@@UAE@XZ) referenced in function "public: virtual __thiscall CChatClientDlg::~CChatClientDlg(void)" (??1CChatClientDlg@@UAE@XZ) ChatClient.obj
Can you help there
|
|
|
|
|
I'm trying too.. Anyone can reply to this question?
|
|
|
|
|
You have done very good job.
Thanks a lot.
|
|
|
|
|
|
As I will develop a program with a server and many clients, I should use IOCP to serve many clients at the same time, So can I modify NDK with IOCP(In/Out completion port),is it feasible?
|
|
|
|
|
The NDK already support many clients. Try my chat sample with 2 or more clients. I don't know about IOCP.
Good luck
Sébastien
|
|
|
|
|
I have tried NDK 2.0 in my program, but I have some trouble in the application. For instance, I send files at the same time, but the server can't capture a lot of messages at the same time, then the message is lost, and the transformation of file aborts. I think the server work as a single thread,it can't deal with multi message at the same time. Could you give some suggestions to use NDK to make server response to many clients at the same time? 
|
|
|
|
|
Hi,
Did you check my other article that show how to write a file transfer?
For multithreading, you should consult the CSocket MFC class because the NDK is just a layer over this class.
Sébastien
|
|
|
|
|
Hi,
Yes, I have readed the program of file transfer.
I have a new problem: if I send a message many times at the same time(with no delay), the server will receive only one message, the others are all lost. If I send a message with a delay of about 30ms, then the server will receive all the messages.
How to make sure that a message is sent to the server successfully? Once I send a message, how long I should wait to send next message?
Is that the server send a message to client and client should always repy to the server?
Thanks very much!
|
|
|
|
|
I have succeeded in creating server-client connection and sending message. But the problem occured when I tried to send message inter-client more than ONCE! So first attempt is always succeeded and the rest are failed.
Testing condition:
I use only one local workstation to test the app. I ran 2 client apps and 1 server.
The problem is the second attempt and so on, the message shown up in the client app that send the message itself, not in the other client app.
Is it normal?
If not, how to fix this?
Thank you.
|
|
|
|
|
Hi,
For this one, I do not have the time debugging it. You can use my chat sample to test how the messaging works.
Good luck
Sébastien
|
|
|
|
|
I have succeeded in using all the NDK class. But one problem I still need to encounter is on SERVER side of how to REMOVE CLIENT that has been "ABNORMALLY DISCONNECTED" maybe because their computer hang or something unexpected that make them impossible to close the application. Therefore, the disconnect message won't be sent to server.
I have tried to add OnClose function on both NDKServer and NDKClient class but the application won't go there in all conditions.
I have read on your comment that OnDisconnect will handle unexpected disconnect condition but it did not functioned.
How to handle this?
I really need this. Because this is the only thing left unsolved.
I look forward to hear from you soon.
Thank you.
|
|
|
|
|
Hi,
This is perferctly normal that you don't receive a message from the client. Suppose his computer is shutoff, the message will never be sent.
When the server will send another message to the client, this time an error message will occur.
Sébastien
|
|
|
|
|
So how to handle that condition? I mean if the client suddenly shut off, I am worry about the pointer that is left unreleased on server and it will make some problem with the server.
I still don't understand how is your method( NDK ) on the Server side to release the clients socket? As far as I can understand, it only delete the user ID from the CMap variable.
Is it not necessary to handle releasing the pointers?
Thank you.
modified on Monday, September 29, 2008 9:30 PM
|
|
|
|
|
The server will remove the pointer. You can verify it by going in the Task Manager then kill the client process. After that send a message to this client from the server.
Sébastien
|
|
|
|
|
I also experiencing a problem of sending message for the second time and so on.
The possibilities of error increase greatly when the client-client / client-server message sending is done more than once.
First time is always Ok.
What was wrong? Does the ProcessPendingRead or ProcessPendingAccept has something to do with the problem?
Thank you.
|
|
|
|
|
It should work
I don't have the time to help you more unfortunately. Check my 2 samples. (The other one in on my another article).
Sébastien
|
|
|
|
|
Hi
I have encountered a problem when calling SendMessageToUser from a thread function. If the call is made from outside the thread, everything works OK.
Error message:
Debug Assertion Failed
Program ... .exe
File f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\sockcore.cpp
Line: 659
sockcore.cpp line 659: ASSERT(m_hSocket == INVALID_SOCKET || CAsyncSocket::FromHandle(m_hSocket) != NULL);
It is the call to CAsyncSocket::FromHandle that returns NULL. We finally end up in sockcore.cpp line 441:
pSocket = (CAsyncSocket*) pState->m_pmapSocketHandle->GetValueAt((void*)hSocket);
pSocket is 0x00000000 {CAsyncSocket} when the call fails,
pSocket is 0x01420210 {CNDKServerSocket} when the call is made from outside the thread
Do you have any clue on what I should do to make this work?
|
|
|
|
|
Hi,
For any problem related to Socket and Thread, please read the MSDN documentation of the class CSocket.
Thanks
Sébastien
|
|
|
|
|
|
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
|