00001 #include "wxMsg.h"
00002
00014 int wxMsg::send()
00015 { int bytes_sent;
00016 sock->Write(outbuf.data(), outbuf.size());
00017 bytes_sent = sock->LastCount();
00018 if(sock->Error())
00019 { *console << wxT("wxMsg::send() error: ") \
00020 << sock->LastError() << wxT("\n");
00021 }
00022 else if(bytes_sent == sock->LastCount())
00023 {
00024
00025 << wxString(outbuf.data(),*wxConvCurrent,bytes_sent) \
00026 << wxT("\n");
00027 outbuf.clear();
00028 }
00029 else
00030 *console << wxT("wxMsg::send() error: full buffer not sent\n");
00031
00032
00033 return bytes_sent;
00034 }
00035
00047 int wxMsg::recv()
00048 {
00049 const int buflen = 200;
00050 char buf[buflen];
00051 int bytes_recv;
00052
00053 sock->Read(buf, buflen);
00054 bytes_recv = sock->LastCount();
00055 if (sock->Error())
00056 {
00057 *console << wxT("wxMsg::recv() error: ") << sock->LastError() \
00058 << wxT("\n");
00059 }
00060 else if(bytes_recv > 0)
00061 { inbuf.append(buf,bytes_recv);
00062 buf[bytes_recv]='\0';
00063 *console << wxT("Message recieved:\n")
00064 << wxString(buf,*wxConvCurrent,bytes_recv + 1)
00065 << wxT("\n\n");
00066 }
00067 else
00068 *console << wxT("wxMsg::recv(): ???\n");
00069
00070 this->dispatch();
00071
00072 return bytes_recv;
00073 }
00074
00086 void wxMsg::setsock(wxSocketClient *s)
00087 {
00088 sock = s;
00089 }
00090
00102 void wxMsg::setconsole(wxTextCtrl *c)
00103 {
00104 console = c;
00105 }