]> git.saurik.com Git - wxWidgets.git/blob - samples/sockets/client.cpp
prettify and simplify the URL test; use a URL more likely to run a web server than...
[wxWidgets.git] / samples / sockets / client.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: client.cpp
3 // Purpose: Client for wxSocket demo
4 // Author: Guillermo Rodriguez Garcia <guille@iies.es>
5 // Modified by:
6 // Created: 1999/09/19
7 // RCS-ID: $Id$
8 // Copyright: (c) 1999 Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ==========================================================================
13 // declarations
14 // ==========================================================================
15
16 // --------------------------------------------------------------------------
17 // headers
18 // --------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 # pragma hdrstop
25 #endif
26
27 // for all others, include the necessary headers
28 #ifndef WX_PRECOMP
29 # include "wx/wx.h"
30 #endif
31
32 #include "wx/socket.h"
33 #include "wx/url.h"
34 #include "wx/sstream.h"
35 #include "wx/scopeguard.h"
36 #include <memory>
37
38 // --------------------------------------------------------------------------
39 // resources
40 // --------------------------------------------------------------------------
41
42 // the application icon
43 #include "mondrian.xpm"
44
45 // --------------------------------------------------------------------------
46 // classes
47 // --------------------------------------------------------------------------
48
49 // Define a new application type
50 class MyApp : public wxApp
51 {
52 public:
53 virtual bool OnInit();
54 };
55
56 // Define a new frame type: this is going to be our main frame
57 class MyFrame : public wxFrame
58 {
59 public:
60 MyFrame();
61 ~MyFrame();
62
63 // event handlers for File menu
64 void OnQuit(wxCommandEvent& event);
65 void OnAbout(wxCommandEvent& event);
66
67 // event handlers for Socket menu
68 void OnOpenConnection(wxCommandEvent& event);
69 void OnTest1(wxCommandEvent& event);
70 void OnTest2(wxCommandEvent& event);
71 void OnTest3(wxCommandEvent& event);
72 void OnCloseConnection(wxCommandEvent& event);
73
74 #if wxUSE_URL
75 // event handlers for Protocols menu
76 void OnTestURL(wxCommandEvent& event);
77 #endif
78 #if wxUSE_IPV6
79 void OnOpenConnectionIPv6(wxCommandEvent& event);
80 #endif
81
82 void OpenConnection(wxSockAddress::Family family);
83
84 // event handlers for DatagramSocket menu (stub)
85 void OnDatagram(wxCommandEvent& event);
86
87 // socket event handler
88 void OnSocketEvent(wxSocketEvent& event);
89
90 // convenience functions
91 void UpdateStatusBar();
92
93 private:
94 wxSocketClient *m_sock;
95 wxTextCtrl *m_text;
96 wxMenu *m_menuFile;
97 wxMenu *m_menuSocket;
98 wxMenu *m_menuDatagramSocket;
99 wxMenu *m_menuProtocols;
100 wxMenuBar *m_menuBar;
101 bool m_busy;
102
103 // any class wishing to process wxWidgets events must use this macro
104 DECLARE_EVENT_TABLE()
105 };
106
107 // --------------------------------------------------------------------------
108 // constants
109 // --------------------------------------------------------------------------
110
111 // IDs for the controls and the menu commands
112 enum
113 {
114 // menu items
115 CLIENT_QUIT = wxID_EXIT,
116 CLIENT_ABOUT = wxID_ABOUT,
117 CLIENT_OPEN = 100,
118 #if wxUSE_IPV6
119 CLIENT_OPENIPV6,
120 #endif
121 CLIENT_TEST1,
122 CLIENT_TEST2,
123 CLIENT_TEST3,
124 CLIENT_CLOSE,
125 #if wxUSE_URL
126 CLIENT_TESTURL,
127 #endif
128 CLIENT_DGRAM,
129
130 // id for socket
131 SOCKET_ID
132 };
133
134 // --------------------------------------------------------------------------
135 // event tables and other macros for wxWidgets
136 // --------------------------------------------------------------------------
137
138 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
139 EVT_MENU(CLIENT_QUIT, MyFrame::OnQuit)
140 EVT_MENU(CLIENT_ABOUT, MyFrame::OnAbout)
141 EVT_MENU(CLIENT_OPEN, MyFrame::OnOpenConnection)
142 #if wxUSE_IPV6
143 EVT_MENU(CLIENT_OPENIPV6, MyFrame::OnOpenConnectionIPv6)
144 #endif
145 EVT_MENU(CLIENT_TEST1, MyFrame::OnTest1)
146 EVT_MENU(CLIENT_TEST2, MyFrame::OnTest2)
147 EVT_MENU(CLIENT_TEST3, MyFrame::OnTest3)
148 EVT_MENU(CLIENT_CLOSE, MyFrame::OnCloseConnection)
149 EVT_MENU(CLIENT_DGRAM, MyFrame::OnDatagram)
150 #if wxUSE_URL
151 EVT_MENU(CLIENT_TESTURL, MyFrame::OnTestURL)
152 #endif
153 EVT_SOCKET(SOCKET_ID, MyFrame::OnSocketEvent)
154 END_EVENT_TABLE()
155
156 IMPLEMENT_APP(MyApp)
157
158 // ==========================================================================
159 // implementation
160 // ==========================================================================
161
162 // --------------------------------------------------------------------------
163 // the application class
164 // --------------------------------------------------------------------------
165
166 bool MyApp::OnInit()
167 {
168 if ( !wxApp::OnInit() )
169 return false;
170
171 // Create the main application window
172 MyFrame *frame = new MyFrame();
173
174 // Show it and tell the application that it's our main window
175 frame->Show(true);
176 SetTopWindow(frame);
177
178 // success
179 return true;
180 }
181
182 // --------------------------------------------------------------------------
183 // main frame
184 // --------------------------------------------------------------------------
185
186 // frame constructor
187 MyFrame::MyFrame() : wxFrame((wxFrame *)NULL, wxID_ANY,
188 _("wxSocket demo: Client"),
189 wxDefaultPosition, wxSize(300, 200))
190 {
191 // Give the frame an icon
192 SetIcon(wxICON(mondrian));
193
194 // Make menus
195 m_menuFile = new wxMenu();
196 m_menuFile->Append(CLIENT_ABOUT, _("&About...\tCtrl-A"), _("Show about dialog"));
197 m_menuFile->AppendSeparator();
198 m_menuFile->Append(CLIENT_QUIT, _("E&xit\tAlt-X"), _("Quit client"));
199
200 m_menuSocket = new wxMenu();
201 m_menuSocket->Append(CLIENT_OPEN, _("&Open session"), _("Connect to server"));
202 #if wxUSE_IPV6
203 m_menuSocket->Append(CLIENT_OPENIPV6, _("&Open session(IPv6)"), _("Connect to server(IPv6)"));
204 #endif
205 m_menuSocket->AppendSeparator();
206 m_menuSocket->Append(CLIENT_TEST1, _("Test &1"), _("Test basic functionality"));
207 m_menuSocket->Append(CLIENT_TEST2, _("Test &2"), _("Test ReadMsg and WriteMsg"));
208 m_menuSocket->Append(CLIENT_TEST3, _("Test &3"), _("Test large data transfer"));
209 m_menuSocket->AppendSeparator();
210 m_menuSocket->Append(CLIENT_CLOSE, _("&Close session"), _("Close connection"));
211
212 m_menuDatagramSocket = new wxMenu();
213 m_menuDatagramSocket->Append(CLIENT_DGRAM, _("Send Datagram"), _("Test UDP sockets"));
214
215 #if wxUSE_URL
216 m_menuProtocols = new wxMenu();
217 m_menuProtocols->Append(CLIENT_TESTURL, _("Test URL\tCtrl-U"),
218 _("Get data from the specified URL"));
219 #endif
220
221 // Append menus to the menubar
222 m_menuBar = new wxMenuBar();
223 m_menuBar->Append(m_menuFile, _("&File"));
224 m_menuBar->Append(m_menuSocket, _("&SocketClient"));
225 m_menuBar->Append(m_menuDatagramSocket, _("&DatagramSocket"));
226 #if wxUSE_URL
227 m_menuBar->Append(m_menuProtocols, _("&Protocols"));
228 #endif
229 SetMenuBar(m_menuBar);
230
231 #if wxUSE_STATUSBAR
232 // Status bar
233 CreateStatusBar(2);
234 #endif // wxUSE_STATUSBAR
235
236 // Make a textctrl for logging
237 m_text = new wxTextCtrl(this, wxID_ANY,
238 _("Welcome to wxSocket demo: Client\nClient ready\n"),
239 wxDefaultPosition, wxDefaultSize,
240 wxTE_MULTILINE | wxTE_READONLY);
241 delete wxLog::SetActiveTarget(new wxLogTextCtrl(m_text));
242
243 // Create the socket
244 m_sock = new wxSocketClient();
245
246 // Setup the event handler and subscribe to most events
247 m_sock->SetEventHandler(*this, SOCKET_ID);
248 m_sock->SetNotify(wxSOCKET_CONNECTION_FLAG |
249 wxSOCKET_INPUT_FLAG |
250 wxSOCKET_LOST_FLAG);
251 m_sock->Notify(true);
252
253 m_busy = false;
254 UpdateStatusBar();
255 }
256
257 MyFrame::~MyFrame()
258 {
259 // No delayed deletion here, as the frame is dying anyway
260 delete m_sock;
261 }
262
263 // event handlers
264
265 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
266 {
267 // true is to force the frame to close
268 Close(true);
269 }
270
271 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
272 {
273 wxMessageBox(_("wxSocket demo: Client\n(c) 1999 Guillermo Rodriguez Garcia\n"),
274 _("About Client"),
275 wxOK | wxICON_INFORMATION, this);
276 }
277
278 void MyFrame::OnOpenConnection(wxCommandEvent& WXUNUSED(event))
279 {
280 OpenConnection(wxSockAddress::IPV4);
281 }
282 #if wxUSE_IPV6
283 void MyFrame::OnOpenConnectionIPv6(wxCommandEvent& WXUNUSED(event))
284 {
285 OpenConnection(wxSockAddress::IPV6);
286 }
287 #endif // wxUSE_IPV6
288
289 void MyFrame::OpenConnection(wxSockAddress::Family family)
290 {
291 wxUnusedVar(family); // unused in !wxUSE_IPV6 case
292
293 wxIPaddress * addr;
294 wxIPV4address addr4;
295 #if wxUSE_IPV6
296 wxIPV6address addr6;
297 if ( family == wxSockAddress::IPV6 )
298 addr = &addr6;
299 else
300 #endif
301 addr = &addr4;
302
303 m_menuSocket->Enable(CLIENT_OPEN, false);
304 #if wxUSE_IPV6
305 m_menuSocket->Enable(CLIENT_OPENIPV6, false);
306 #endif
307 m_menuSocket->Enable(CLIENT_CLOSE, false);
308
309 // Ask user for server address
310 wxString hostname = wxGetTextFromUser(
311 _("Enter the address of the wxSocket demo server:"),
312 _("Connect ..."),
313 _("localhost"));
314
315 addr->Hostname(hostname);
316 addr->Service(3000);
317
318 // Mini-tutorial for Connect() :-)
319 // ---------------------------
320 //
321 // There are two ways to use Connect(): blocking and non-blocking,
322 // depending on the value passed as the 'wait' (2nd) parameter.
323 //
324 // Connect(addr, true) will wait until the connection completes,
325 // returning true on success and false on failure. This call blocks
326 // the GUI (this might be changed in future releases to honour the
327 // wxSOCKET_BLOCK flag).
328 //
329 // Connect(addr, false) will issue a nonblocking connection request
330 // and return immediately. If the return value is true, then the
331 // connection has been already successfully established. If it is
332 // false, you must wait for the request to complete, either with
333 // WaitOnConnect() or by watching wxSOCKET_CONNECTION / LOST
334 // events (please read the documentation).
335 //
336 // WaitOnConnect() itself never blocks the GUI (this might change
337 // in the future to honour the wxSOCKET_BLOCK flag). This call will
338 // return false on timeout, or true if the connection request
339 // completes, which in turn might mean:
340 //
341 // a) That the connection was successfully established
342 // b) That the connection request failed (for example, because
343 // it was refused by the peer.
344 //
345 // Use IsConnected() to distinguish between these two.
346 //
347 // So, in a brief, you should do one of the following things:
348 //
349 // For blocking Connect:
350 //
351 // bool success = client->Connect(addr, true);
352 //
353 // For nonblocking Connect:
354 //
355 // client->Connect(addr, false);
356 //
357 // bool waitmore = true;
358 // while (! client->WaitOnConnect(seconds, millis) && waitmore )
359 // {
360 // // possibly give some feedback to the user,
361 // // update waitmore if needed.
362 // }
363 // bool success = client->IsConnected();
364 //
365 // And that's all :-)
366
367 m_text->AppendText(_("\nTrying to connect (timeout = 10 sec) ...\n"));
368 m_sock->Connect(*addr, false);
369 m_sock->WaitOnConnect(10);
370
371 if (m_sock->IsConnected())
372 m_text->AppendText(_("Succeeded ! Connection established\n"));
373 else
374 {
375 m_sock->Close();
376 m_text->AppendText(_("Failed ! Unable to connect\n"));
377 wxMessageBox(_("Can't connect to the specified host"), _("Alert !"));
378 }
379
380 UpdateStatusBar();
381 }
382
383 void MyFrame::OnTest1(wxCommandEvent& WXUNUSED(event))
384 {
385 // Disable socket menu entries (exception: Close Session)
386 m_busy = true;
387 UpdateStatusBar();
388
389 m_text->AppendText(_("\n=== Test 1 begins ===\n"));
390
391 // Tell the server which test we are running
392 unsigned char c = 0xBE;
393 m_sock->Write(&c, 1);
394
395 // Send some data and read it back. We know the size of the
396 // buffer, so we can specify the exact number of bytes to be
397 // sent or received and use the wxSOCKET_WAITALL flag. Also,
398 // we have disabled menu entries which could interfere with
399 // the test, so we can safely avoid the wxSOCKET_BLOCK flag.
400 //
401 // First we send a byte with the length of the string, then
402 // we send the string itself (do NOT try to send any integral
403 // value larger than a byte "as is" across the network, or
404 // you might be in trouble! Ever heard about big and little
405 // endian computers?)
406
407 m_sock->SetFlags(wxSOCKET_WAITALL);
408
409 const wxChar *buf1 = _T("Test string (less than 256 chars!)");
410 unsigned char len = (unsigned char)((wxStrlen(buf1) + 1)*sizeof(wxChar));
411 wxChar *buf2 = new wxChar[wxStrlen(buf1) + 1];
412
413 m_text->AppendText(_("Sending a test buffer to the server ..."));
414 m_sock->Write(&len, 1);
415 m_sock->Write(buf1, len);
416 m_text->AppendText(m_sock->Error() ? _("failed !\n") : _("done\n"));
417
418 m_text->AppendText(_("Receiving the buffer back from server ..."));
419 m_sock->Read(buf2, len);
420 m_text->AppendText(m_sock->Error() ? _("failed !\n") : _("done\n"));
421
422 m_text->AppendText(_("Comparing the two buffers ..."));
423 if (memcmp(buf1, buf2, len) != 0)
424 {
425 m_text->AppendText(_("failed!\n"));
426 m_text->AppendText(_("Test 1 failed !\n"));
427 }
428 else
429 {
430 m_text->AppendText(_("done\n"));
431 m_text->AppendText(_("Test 1 passed !\n"));
432 }
433 m_text->AppendText(_("=== Test 1 ends ===\n"));
434
435 delete[] buf2;
436 m_busy = false;
437 UpdateStatusBar();
438 }
439
440 void MyFrame::OnTest2(wxCommandEvent& WXUNUSED(event))
441 {
442 const wxChar *msg1;
443 wxChar *msg2;
444 size_t len;
445
446 // Disable socket menu entries (exception: Close Session)
447 m_busy = true;
448 UpdateStatusBar();
449
450 m_text->AppendText(_("\n=== Test 2 begins ===\n"));
451
452 // Tell the server which test we are running
453 unsigned char c = 0xCE;
454 m_sock->Write(&c, 1);
455
456 // Here we use ReadMsg and WriteMsg to send messages with
457 // a header with size information. Also, the reception is
458 // event triggered, so we test input events as well.
459 //
460 // We need to set no flags here (ReadMsg and WriteMsg are
461 // not affected by flags)
462
463 m_sock->SetFlags(wxSOCKET_WAITALL);
464
465 wxString s = wxGetTextFromUser(
466 _("Enter an arbitrary string to send to the server:"),
467 _("Test 2 ..."),
468 _("Yes I like wxWidgets!"));
469
470 msg1 = s.c_str();
471 len = (wxStrlen(msg1) + 1) * sizeof(wxChar);
472 msg2 = new wxChar[wxStrlen(msg1) + 1];
473
474 m_text->AppendText(_("Sending the string with WriteMsg ..."));
475 m_sock->WriteMsg(msg1, len);
476 m_text->AppendText(m_sock->Error() ? _("failed !\n") : _("done\n"));
477 m_text->AppendText(_("Waiting for an event (timeout = 2 sec)\n"));
478
479 // Wait until data available (will also return if the connection is lost)
480 m_sock->WaitForRead(2);
481
482 if (m_sock->IsData())
483 {
484 m_text->AppendText(_("Reading the string back with ReadMsg ..."));
485 m_sock->ReadMsg(msg2, len);
486 m_text->AppendText(m_sock->Error() ? _("failed !\n") : _("done\n"));
487 m_text->AppendText(_("Comparing the two buffers ..."));
488 if (memcmp(msg1, msg2, len) != 0)
489 {
490 m_text->AppendText(_("failed!\n"));
491 m_text->AppendText(_("Test 2 failed !\n"));
492 }
493 else
494 {
495 m_text->AppendText(_("done\n"));
496 m_text->AppendText(_("Test 2 passed !\n"));
497 }
498 }
499 else
500 m_text->AppendText(_("Timeout ! Test 2 failed.\n"));
501
502 m_text->AppendText(_("=== Test 2 ends ===\n"));
503
504 delete[] msg2;
505 m_busy = false;
506 UpdateStatusBar();
507 }
508
509 void MyFrame::OnTest3(wxCommandEvent& WXUNUSED(event))
510 {
511 char *buf1;
512 char *buf2;
513 unsigned char len;
514
515 // Disable socket menu entries (exception: Close Session)
516 m_busy = true;
517 UpdateStatusBar();
518
519 m_text->AppendText(_("\n=== Test 3 begins ===\n"));
520
521 // Tell the server which test we are running
522 unsigned char c = 0xDE;
523 m_sock->Write(&c, 1);
524
525 // This test also is similar to the first one but it sends a
526 // large buffer so that wxSocket is actually forced to split
527 // it into pieces and take care of sending everything before
528 // returning.
529
530 m_sock->SetFlags(wxSOCKET_WAITALL);
531
532 // Note that len is in kbytes here!
533 len = 32;
534 buf1 = new char[len * 1024];
535 buf2 = new char[len * 1024];
536
537 for (int i = 0; i < len * 1024; i ++)
538 buf1[i] = (char)(i % 256);
539
540 m_text->AppendText(_("Sending a large buffer (32K) to the server ..."));
541 m_sock->Write(&len, 1);
542 m_sock->Write(buf1, len * 1024);
543 m_text->AppendText(m_sock->Error() ? _("failed !\n") : _("done\n"));
544
545 m_text->AppendText(_("Receiving the buffer back from server ..."));
546 m_sock->Read(buf2, len * 1024);
547 m_text->AppendText(m_sock->Error() ? _("failed !\n") : _("done\n"));
548
549 m_text->AppendText(_("Comparing the two buffers ..."));
550 if (memcmp(buf1, buf2, len) != 0)
551 {
552 m_text->AppendText(_("failed!\n"));
553 m_text->AppendText(_("Test 3 failed !\n"));
554 }
555 else
556 {
557 m_text->AppendText(_("done\n"));
558 m_text->AppendText(_("Test 3 passed !\n"));
559 }
560 m_text->AppendText(_("=== Test 3 ends ===\n"));
561
562 delete[] buf2;
563 m_busy = false;
564 UpdateStatusBar();
565 }
566
567 void MyFrame::OnCloseConnection(wxCommandEvent& WXUNUSED(event))
568 {
569 m_sock->Close();
570 UpdateStatusBar();
571 }
572
573 void MyFrame::OnDatagram(wxCommandEvent& WXUNUSED(event))
574 {
575 m_text->AppendText(_("\n=== Datagram test begins ===\n"));
576 m_text->AppendText(_("Sorry, not implemented\n"));
577 m_text->AppendText(_("=== Datagram test ends ===\n"));
578 }
579
580 #if wxUSE_URL
581
582 void MyFrame::OnTestURL(wxCommandEvent& WXUNUSED(event))
583 {
584 // Ask for the URL
585 static wxString s_urlname("http://www.google.com/");
586 wxString urlname = wxGetTextFromUser
587 (
588 _("Enter an URL to get"),
589 _("URL:"),
590 s_urlname
591 );
592 if ( urlname.empty() )
593 return; // cancelled by user
594
595 s_urlname = urlname;
596
597
598 wxLogMessage("=== URL test begins ===");
599 wxON_BLOCK_EXIT1( wxLogMessage, "=== URL test ends ===" );
600
601 // Parse the URL
602 wxURL url(urlname);
603 if ( url.GetError() != wxURL_NOERR )
604 {
605 wxLogError("Failed to parse URL \"%s\"", urlname);
606 return;
607 }
608
609 // Try to get the input stream (connects to the given URL)
610 wxLogMessage("Establishing connection to \"%s\"...", urlname);
611 const std::auto_ptr<wxInputStream> data(url.GetInputStream());
612 if ( !data.get() )
613 {
614 wxLogError("Failed to retrieve URL \"%s\"", urlname);
615 return;
616 }
617
618 // Print the contents type and file size
619 wxLogMessage("Contents type: %s\nFile size: %i\nStarting to download...",
620 url.GetProtocol().GetContentType(),
621 data->GetSize());
622
623 // Get the data
624 wxStringOutputStream sout;
625 if ( data->Read(sout).GetLastError() != wxSTREAM_EOF )
626 wxLogError("Error reading the input stream.");
627
628 wxLogMessage("Text retrieved from URL \"%s\" follows:\n%s",
629 urlname, sout.GetString());
630 }
631
632 #endif // wxUSE_URL
633
634 void MyFrame::OnSocketEvent(wxSocketEvent& event)
635 {
636 wxString s = _("OnSocketEvent: ");
637
638 switch(event.GetSocketEvent())
639 {
640 case wxSOCKET_INPUT : s.Append(_("wxSOCKET_INPUT\n")); break;
641 case wxSOCKET_LOST : s.Append(_("wxSOCKET_LOST\n")); break;
642 case wxSOCKET_CONNECTION : s.Append(_("wxSOCKET_CONNECTION\n")); break;
643 default : s.Append(_("Unexpected event !\n")); break;
644 }
645
646 m_text->AppendText(s);
647 UpdateStatusBar();
648 }
649
650 // convenience functions
651
652 void MyFrame::UpdateStatusBar()
653 {
654 wxString s;
655
656 if (!m_sock->IsConnected())
657 {
658 s.Printf(_("Not connected"));
659 }
660 else
661 {
662 #if wxUSE_IPV6
663 wxIPV6address addr;
664 #else
665 wxIPV4address addr;
666 #endif
667
668 m_sock->GetPeer(addr);
669 s.Printf(_("%s : %d"), (addr.Hostname()).c_str(), addr.Service());
670 }
671
672 #if wxUSE_STATUSBAR
673 SetStatusText(s, 1);
674 #endif // wxUSE_STATUSBAR
675
676 m_menuSocket->Enable(CLIENT_OPEN, !m_sock->IsConnected() && !m_busy);
677 #if wxUSE_IPV6
678 m_menuSocket->Enable(CLIENT_OPENIPV6, !m_sock->IsConnected() && !m_busy);
679 #endif
680 m_menuSocket->Enable(CLIENT_TEST1, m_sock->IsConnected() && !m_busy);
681 m_menuSocket->Enable(CLIENT_TEST2, m_sock->IsConnected() && !m_busy);
682 m_menuSocket->Enable(CLIENT_TEST3, m_sock->IsConnected() && !m_busy);
683 m_menuSocket->Enable(CLIENT_CLOSE, m_sock->IsConnected());
684 }