|
I'm not too sure about exceptions when it comes to winsock stuff, but try adding a check for bytesRecv == 0, and if so break:
if ((bytesRecv = recv(m_socket, recvbuf, 5, 0)) == 0)<br />
break;<br />
else<br />
....
If the other end of the link disconnects cleanly then recv should return 0 (zero bytes received). You would then, in the server, go back to a listen state waiting for a new connection. The reason you're printing out the last thing the server recieved over-and-over is because, as there's nothing to recv the buffer doesn't get overwritten.
Of course, this is all assuming you're using a connection oriented socket (TCP).
In theory the exception should pick up on the dropped connection, but as I say, I've not used exceptions with winsock comms.
Hope that's:
a) correct
b) helpful
Cheers, 'bod
|
|
|
|
|
icabod wrote:
I've not used exceptions with winsock comms.
Which is very bad programming practice. <slaps wrist>
|
|
|
|
|
instead of 0 if we check for -1 its working fine... i can trap it..
thanks,
V
|
|
|
|
|
Like I said, I've not used exceptions with winsock, so I'm not sure what it would catch. The recv will return 0 for a cleanly-disconnected socket, and -1 for some other error. I would have thought that the exception would catch the -1 case, leaving you to handle just the clean closure of the client.
But hey, if it works, it works
'bod
|
|
|
|
|
hey buddy great man.. its working.. thanks a lot..
its Correct and its Helpful so thanx,thanx,thanx,thanx,thanx,thanx,
V
|
|
|
|
|
yes it will loop indefinately even if the client gets disconnected as catch() is not executed after the client is disconnected(ie.,bytesRecv =0).put the try catch on return value from recv.
|
|
|
|
|
sunit5 wrote:
put the try catch on return value from recv.
?? return value can trow an Exception? r u sure? i'll try that too
V
|
|
|
|
|
tssss,
try / catch statement is used ONLY to catch thrown exceptions.
if no exception is thrown, you will never enter the bloc.
if you want to perform certain action depending a function result, just test it the simple way.
Vivekuniq wrote:
return value can trow an Exception?
no. but the function which is call and suspected to return a value can not execute well to its end and throw an exception before the return instruction.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
in java we have a particular Exception thrown when it finds the client is disconnected..just like
try
{
}
catch(UnknownHostExeption e)// not sure some other exception here
{
}
do we have something like that in C++ (winsock)..?
Thnx
V
|
|
|
|
|
that what i tried to explain u waht toxxct said.dont put try and catch.better use if and else(test by yourself).msdn has mentioned if any exception thrown by an API
|
|
|
|
|
this is my code for useing ADO link Paradox DataBase.
but it throw wrong so maybe you can help me.
i will greatly appreciated
BOOL CTM21App::InitInstance()
{
CString connectsource;
_ConnectionPtr pCon;
AfxOleInit();
AfxEnableControlContainer();
pCon.CreateInstance(__uuidof(Connection));
try
{
connectsource.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%d\\work\TM21Vol4\gentan500\Database;Extended Properties=Paradox 4.81ersist Security Info=False");
pCon->Open((_bstr_t)connectsource,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox("open .db wrong");
return FALSE;
}
}
nothing
|
|
|
|
|
I just download a server and client source code. But I do not know how to build it as my project. Can somebody give some guide.....I really a fool of computer programming...
|
|
|
|
|
Hi,
For compiling, you need a compiler. A compiler is free when you buy an IDE
You can buy one here at codeproject with some discount, or download the free trial of Visual Studio 2005 beta.
Then open the project file and press the Build button. If you don't even know how to build, maybe it's an idea to ask the developers of the application to build it for you?
Geert
Want to spread the newest version of your software automatically for free? Use Updater!
Visit my website: www.gvhsoftware.org
|
|
|
|
|
The source code that I downloaded are all in .cpp and .h and I don't know how to test it. I mean when I open the Visual C++ software and open the source code and click on the Rebuild button, it will prompt me to build a default workspaces. So,I click OK and it will compile. But I don't know how to link all the source code together so that I can compile and execute, and come out a DOS which is the final result of the source code. Hope that you understand what I was asking. I really don't know how to express my question.
I just want to use all the source code to become my project source code. The source code that I downloaded have two folder, one is client and another is server.
|
|
|
|
|
I hope there is more than just source files.
Isn't there a DSW or DSP file? You have to open that one (just use File -> Open project or Open workspace).
then you should be able to build (if you don't require platform sdk updates or something like that)
Geert
Want to spread the newest version of your software automatically for free? Use Updater!
Visit my website: www.gvhsoftware.org
|
|
|
|
|
Usually there is a build instruction in the readme file...
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
But the source code that I downloaded dont't have readme file. It just have .cpp and .h file
|
|
|
|
|
Details please but it sounds like you have downloaded just a class not the sample project.
Elaine
The tigress is here
|
|
|
|
|
me think you need to include the server files in your server project and the client files in your client project.
I assume that you know how to create and manage a simple project with Visual Studio ( vc6 or vs.net )
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
hello,
I have inserted a maximize button in my dialog box title bar.Now using the OnSize handler i want to set the size of dialog box myself.So what i am doing is that when i press Maximize button i call MoveWindow() function in OnSize() handler and then the size of dialog should be set.this i am doing since i dont want the usually output of maximize button(whole screen is occupied by the dialog).I want the dialog to be increased in size upto only a certain height.
But whatever the size i am setting from MoveWindow for the dialog,initially itself size of dialog is set to that size.(without me pressing the Maximize button).
I searched on net and found a document stating that when dialog is created some default window handlers are called.Out of these OnSize is one.So the code for MoveWindow() is executed at creation only?Is this true?
Please help...
i am not sure whether i am proceeding in right direction....
if not what should i do?
thanks
|
|
|
|
|
OnSize is called at initialization.
You can prevent your OnSize handler code from executing the first time by using a bool variable that is set to false in the class constructor. And at the end of OnInitDialog(), you set it to true. And check if it is true in OnSize(), and if it is true, only then call MoveWindow() or whatever you want to do in OnSize().
this is this.
|
|
|
|
|
Hi,
check out the OnGetMinMaxInfo() handler.
In the class-wizard it's a window message not a dialog message.
Regards
|
|
|
|
|
sayup wrote:
using the OnSize handler i want to set the size of dialog box myself.
I think you'd be better off handling WM_SYSCOMMAND and resizing the window to the desired size for the SC_MAXIMIZE case.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Is this from experience? The MINMAXINFO Structure definitely has a field for entering the MAXIMUM size of the window, so why wouldn't filling that in be enough?
|
|
|
|
|
Blake Miller wrote:
Is this from experience?
Yes, but handling WM_GETMINMAXINFO should also work.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|