codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
/*************************************************************** * Name: Crypted_Ip2Ip_chatMain.cpp * Purpose: Code for Application Frame * Author: Rada Florin Daniel (florin.rada87@yahoo.com) * Created: 2012-04-08 * Copyright: Rada Florin Daniel () * License: **************************************************************/ #include "Crypted_Ip2Ip_chatMain.h" #include <wx/msgdlg.h> //(*InternalHeaders(Crypted_Ip2Ip_chatFrame) #include <wx/intl.h> #include <wx/string.h> //*) #include <wx/textdlg.h> #include <wx/tokenzr.h> //helper functions enum wxbuildinfoformat { short_f, long_f }; wxString wxbuildinfo(wxbuildinfoformat format) { wxString wxbuild(wxVERSION_STRING); if (format == long_f ) { #if defined(__WXMSW__) wxbuild << _T("-Windows"); #elif defined(__UNIX__) wxbuild << _T("-Linux"); #endif #if wxUSE_UNICODE wxbuild << _T("-Unicode build"); #else wxbuild << _T("-ANSI build"); #endif // wxUSE_UNICODE } return wxbuild; } const long Crypted_Ip2Ip_chatFrame::ID_TP_CLASA_A = 4001; const long Crypted_Ip2Ip_chatFrame::ID_TP_CLASA_B = 4002; const long Crypted_Ip2Ip_chatFrame::ID_TP_CLASA_C = 4003; const long Crypted_Ip2Ip_chatFrame::ID_TP_CLASA_D = 4004; //(*IdInit(Crypted_Ip2Ip_chatFrame const long Crypted_Ip2Ip_chatFrame::ID_STATICTEXT1 = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_STATICTEXT2 = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_TP_PORT = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_BP_CONNECT = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_BP_DISCONNECT = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_TP_OUT = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_TP_INPUT = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_BP_SEND = wxNewId(); const long Crypted_Ip2Ip_chatFrame::idMenuQuit = wxNewId(); const long Crypted_Ip2Ip_chatFrame::idMenuAbout = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_STATUSBAR1 = wxNewId(); //* const int Crypted_Ip2Ip_chatFrame::SERVER_ID = wxNewId(); const int Crypted_Ip2Ip_chatFrame::CONN_ID = wxNewId(); const long Crypted_Ip2Ip_chatFrame::ID_SETARI_PORT = wxNewId(); const int Crypted_Ip2Ip_chatFrame::MAX_POINTS = 3; BEGIN_EVENT_TABLE(Crypted_Ip2Ip_chatFrame,wxFrame) //(*EventTable(Crypted_Ip2Ip_chatFrame) //*) EVT_TEXT(ID_TP_PORT, Crypted_Ip2Ip_chatFrame::onPortUpdate) EVT_SOCKET(SERVER_ID, Crypted_Ip2Ip_chatFrame::onServerEvent) EVT_SOCKET(CONN_ID, Crypted_Ip2Ip_chatFrame::onSocketInput)\ EVT_TEXT_ENTER(ID_TP_INPUT, Crypted_Ip2Ip_chatFrame::Onbp_sendClick) END_EVENT_TABLE() Crypted_Ip2Ip_chatFrame::Crypted_Ip2Ip_chatFrame(wxWindow* parent,wxWindowID id) { //(*Initialize(Crypted_Ip2Ip_chatFrame) wxMenuItem* MenuItem2; wxMenuItem* MenuItem1; wxBoxSizer* BoxSizer2; wxMenu* Menu1; wxBoxSizer* BoxSizer1; wxMenuBar* MenuBar1; wxFlexGridSizer* FlexGridSizer1; wxBoxSizer* BoxSizer3; wxMenu* Menu2; Create(parent, id, _("Crypted Ip2Ip chat"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE, _T("id")); FlexGridSizer1 = new wxFlexGridSizer(4, 1, 0, 0); FlexGridSizer1->AddGrowableCol(0); FlexGridSizer1->AddGrowableRow(1); BoxSizer1 = new wxBoxSizer(wxHORIZONTAL); StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Adresa"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1")); BoxSizer1->Add(StaticText1, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); tp_clasaA = new wxTextCtrl(this, ID_TP_CLASA_A, wxEmptyString, wxDefaultPosition, wxSize(35,21), 0, wxDefaultValidator, _T("ID_TP_CLASA_A")); tp_clasaA->SetMaxLength(3); BoxSizer1->Add(tp_clasaA, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); tp_clasaB = new wxTextCtrl(this, ID_TP_CLASA_B, wxEmptyString, wxDefaultPosition, wxSize(35,21), 0, wxDefaultValidator, _T("ID_TP_CLASA_B")); tp_clasaB->SetMaxLength(3); BoxSizer1->Add(tp_clasaB, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); tp_clasaC = new wxTextCtrl(this, ID_TP_CLASA_C, wxEmptyString, wxDefaultPosition, wxSize(35,21), 0, wxDefaultValidator, _T("ID_TP_CLASA_C")); tp_clasaC->SetMaxLength(3); BoxSizer1->Add(tp_clasaC, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); tp_clasaD = new wxTextCtrl(this, ID_TP_CLASA_D, wxEmptyString, wxDefaultPosition, wxSize(35,21), 0, wxDefaultValidator, _T("ID_TP_CLASA_D")); tp_clasaD->SetMaxLength(3); BoxSizer1->Add(tp_clasaD, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Port:"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2")); BoxSizer1->Add(StaticText2, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); tp_port = new wxTextCtrl(this, ID_TP_PORT, wxEmptyString, wxDefaultPosition, wxSize(47,23), 0, wxDefaultValidator, _T("ID_TP_PORT")); tp_port->SetMaxLength(5); BoxSizer1->Add(tp_port, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); bp_connect = new wxButton(this, ID_BP_CONNECT, _("Connect"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BP_CONNECT")); BoxSizer1->Add(bp_connect, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); bp_disconnect = new wxButton(this, ID_BP_DISCONNECT, _("Disconnect"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BP_DISCONNECT")); BoxSizer1->Add(bp_disconnect, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); FlexGridSizer1->Add(BoxSizer1, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); BoxSizer2 = new wxBoxSizer(wxVERTICAL); tp_out = new wxTextCtrl(this, ID_TP_OUT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_WORDWRAP, wxDefaultValidator, _T("ID_TP_OUT")); tp_out->SetMinSize(wxSize(400,200)); BoxSizer2->Add(tp_out, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); FlexGridSizer1->Add(BoxSizer2, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_TOP, 5); BoxSizer3 = new wxBoxSizer(wxHORIZONTAL); tp_input = new wxTextCtrl(this, ID_TP_INPUT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxHSCROLL, wxDefaultValidator, _T("ID_TP_INPUT")); tp_input->SetMaxLength(512); tp_input->SetMinSize(wxSize(400,50)); BoxSizer3->Add(tp_input, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_TOP, 5); bp_send = new wxButton(this, ID_BP_SEND, _("Send"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BP_SEND")); BoxSizer3->Add(bp_send, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); FlexGridSizer1->Add(BoxSizer3, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); SetSizer(FlexGridSizer1); MenuBar1 = new wxMenuBar(); Menu1 = new wxMenu(); MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL); Menu1->Append(MenuItem1); MenuBar1->Append(Menu1, _("&File")); Menu2 = new wxMenu(); MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL); Menu2->Append(MenuItem2); MenuBar1->Append(Menu2, _("Help")); SetMenuBar(MenuBar1); StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1")); int __wxStatusBarWidths_1[1] = { -1 }; int __wxStatusBarStyles_1[1] = { wxSB_NORMAL }; StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1); StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1); SetStatusBar(StatusBar1); FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); Connect(ID_BP_CONNECT,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Crypted_Ip2Ip_chatFrame::Onbp_connectClick); Connect(ID_BP_DISCONNECT,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Crypted_Ip2Ip_chatFrame::Onbp_disconnectClick); Connect(ID_BP_SEND,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&Crypted_Ip2Ip_chatFrame::Onbp_sendClick); Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Crypted_Ip2Ip_chatFrame::OnQuit); Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Crypted_Ip2Ip_chatFrame::OnAbout); //*) Connect(4001, 4004, wxEVT_COMMAND_TEXT_UPDATED, (wxObjectEventFunction)&Crypted_Ip2Ip_chatFrame::onClasaUpdate); wxIPV4address addr; addr.AnyAddress(); port_local = wxGetTextFromUser(_("Selecteaza portul pe care sa asculte aplicatia."), _("Alege port"), _("3000")); if(port_local.empty()) { wxString ports = wxString::Format(_("3000")); addr.Service(ports); } else { addr.Service(port_local); } mp_sockServ = new wxSocketServer(addr); while(!mp_sockServ->IsOk()) { port_local = wxGetTextFromUser(_("Portul selectat este deja in uz sau eroare la initializare socket.\nIntrodu un alt port."), _("Alege port.")); mp_sockServ->Destroy(); if(port_local.empty()) { port_local = _("3000"); } addr.Service(port_local); mp_sockServ = new wxSocketServer(addr); } mp_sockServ->SetEventHandler(*this, SERVER_ID); mp_sockServ->SetNotify(wxSOCKET_CONNECTION_FLAG); mp_sockServ->Notify(true); tp_input->Enable(false); bp_send->Enable(false); bp_disconnect->Enable(false); StatusBar1->SetStatusText(_("Ascultam pe portul: ") + port_local); connectat = 0; } Crypted_Ip2Ip_chatFrame::~Crypted_Ip2Ip_chatFrame() { //(*Destroy(Crypted_Ip2Ip_chatFrame) //*) } void Crypted_Ip2Ip_chatFrame::OnQuit(wxCommandEvent& event) { mp_sockClient->Destroy(); mp_sockServ->Destroy(); Close(); } void Crypted_Ip2Ip_chatFrame::OnAbout(wxCommandEvent& event) { wxString msg = wxbuildinfo(long_f); wxMessageBox(msg, _("Welcome to...")); } void Crypted_Ip2Ip_chatFrame::onSeteazaPort(wxCommandEvent& event) { wxMessageBox(_("onSeteazaPORT")); //port = wxGetTextFromUser(); } void Crypted_Ip2Ip_chatFrame::onPortUpdate(wxCommandEvent& event) { size_t pos = tp_port->GetInsertionPoint(); wxString temp = tp_port->GetLineText(0); if(port_extern.size() > temp.size() || tp_port->IsEmpty()) { port_extern = temp; return; } if(temp[(pos - 1)] <= '9' && temp[(pos - 1)] >= '0') { //points_num++; port_extern = temp; return; } else { port_extern = temp.substr(0, pos - 1); tp_port->ChangeValue(port_extern); tp_port->SetInsertionPoint(pos -1); } } // cand apasam pe sent sau apasam enter aceasta metoda este invocata // va prelua tot ce a fost introdus si il va trimite prin mp_sockClient // Eroarea este ca nu void Crypted_Ip2Ip_chatFrame::Onbp_sendClick(wxCommandEvent& event) { wxString s; tp_input->SetInsertionPoint(0); s.clear(); for(int i = 0; i < tp_input->GetNumberOfLines(); i++) { wxString temp = tp_input->GetLineText(i); if(temp.size() <= 0) { continue; } s.append(temp); }/** unsigned char len = (unsigned char)s.size(); mp_sockClient->Write(&len, 1); #if wxUSE_UNICODE mp_sockClient->Write(s.wx_str(), len); #else mp_sockClient->Write(s.mb_str(), len); #endif // wxUSE_UNICODE tp_out->AppendText(_("Eu: ") + s); tp_out->AppendText(_("\n")); tp_input->Clear();*/ //mp_sockClient->Write(s.wx_str(), (s.size() * sizeof(wchar_t))); //const wxChar* buf; s.append(_("\0")); //buf = s.mb_str()); size_t len; //len = (wxStrlen(buf); //mp_sockClient->Write(&len, 1); //wxMessageBox(wxString::Format(_("%i"), len)); mp_sockClient->WriteMsg(s.mb_str(), wxStrlen(s)); size_t write_len = mp_sockClient->LastCount(); //tp_out->AppendText(wxString::Format(_("%i"), write_len)); tp_out->AppendText(_("Eu: ") + s); tp_out->AppendText(_("\n")); tp_input->Clear(); } // executa conexiunea catre un alt utilizator void Crypted_Ip2Ip_chatFrame::Onbp_connectClick(wxCommandEvent& event) { tp_out->Clear(); //wxString adresa = clasaA + "." + clasaB + "." + clasaC + "." + clasaD; // concactam cele 4 clase intr-un ip if(tp_clasaA->IsEmpty() || tp_clasaB->IsEmpty() || tp_clasaC->IsEmpty() || tp_clasaD->IsEmpty()) { wxMessageBox(_("Nu ati introdus ip-ul complet."), _("Eroare."), wxICON_ERROR); return; } if(tp_port->IsEmpty()) { wxMessageBox(_("Nu ati intrudus portul la care trebuie sa va conectati."), _("Eroare."), wxICON_ERROR); return; } port_extern = tp_port->GetLineText(0); wxString adresa = tp_clasaA->GetLineText(0) + _(".") + tp_clasaB->GetLineText(0) + _(".") + tp_clasaC->GetLineText(0) + _(".") + tp_clasaD->GetLineText(0); //wxMessageBox((adresa + port_extern)); wxIPV4address addr; addr.Hostname(adresa); addr.Service(port_extern); // creem noul socket prin care se va face comunicarea cu serverul mp_sockClient = new wxSocketClient(); mp_sockClient->SetEventHandler(*this, CONN_ID); mp_sockClient->SetNotify(wxSOCKET_CONNECTION_FLAG | wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); mp_sockClient->Notify(true); mp_sockClient->Connect(addr, false); mp_sockClient->WaitOnConnect(10); //mp_sockServ->Destroy(); // oprim sockServ , nu avem nevoie sa mai sculte atat timp cat suntem conectati la alt ip bp_connect->Enable(false); // orpim butonul de connect pana primim un raspuns in legatura cu connexiunea. if(mp_sockClient->IsConnected()) { // actualizam status bar StatusBar1->SetStatusText((_("Ne-am connectat cu succes la : ") + adresa)); // oprim input-ul pentr ip, port si butonul de connect. tp_clasaA->Enable(false); tp_clasaB->Enable(false); tp_clasaC->Enable(false); tp_clasaD->Enable(false); tp_port->Enable(false); bp_connect->Enable(false); // pornit inputul pentru chat si butonul de send tp_input->Enable(true); bp_send->Enable(true); //pornim butonul de disconnect bp_disconnect->Enable(true); mp_sockServ->Destroy(); // distrugem sockServer doar daca am reusit sa initiem o noua conexiune. } else { StatusBar1->SetStatusText((_("Nu ne-am putut conecta la : ") + adresa)); //addr.Hostname("localhost"); //addr.Service(port); //mp_sockServ = new wxSocketServer(addr); //mp_sockServ->SetEventHandler(*this, SERVER_ID); //mp_sockServ->SetNotify(wxSOCKET_CONNECTION_FLAG); //mp_sockServ->Notify(true); bp_connect->Enable(true); // repornim butonul de connect mp_sockClient->Close(); } } void Crypted_Ip2Ip_chatFrame::onClasaUpdate(wxCommandEvent& event) { wxTextCtrl* clasa = (wxTextCtrl*)event.GetEventObject(); size_t pos = clasa->GetInsertionPoint(); wxString temp = clasa->GetLineText(0); wxString* p_clasa; char min = '0'; char max = '9'; if(ID_TP_CLASA_A == event.GetId()) { p_clasa = &clasaA; } else if(ID_TP_CLASA_B == event.GetId()) { p_clasa = &clasaB; } else if(ID_TP_CLASA_C == event.GetId()) { p_clasa =&clasaC; } else if(ID_TP_CLASA_D == event.GetId()) { p_clasa = &clasaD; } else { p_clasa = NULL; return; } if(p_clasa->size() > temp.size() || clasa->IsEmpty()) { *p_clasa = temp; return; } if(temp[(pos - 1)] <= max && temp[(pos - 1)] >= min) { if(temp[0] >= '3') { clasa->SetMaxLength(2); } else { clasa->SetMaxLength(3); if(3 == temp.size()) { int temp_num = wxAtoi(temp); if(255 < temp_num) { *p_clasa = temp.SubString(0, 1); clasa->ChangeValue(*p_clasa); clasa->SetInsertionPoint(pos - 1); } } } } else { *p_clasa = temp.substr(0, pos - 1); clasa->ChangeValue(*p_clasa); clasa->SetInsertionPoint(pos -1); } } // Deconecteaza conexiunea void Crypted_Ip2Ip_chatFrame::Onbp_disconnectClick(wxCommandEvent& event) { // -> repornim mp_sockserver pentru ascultare - e distrus atunci cand noi initiem conectarea la alt ip. wxIPV4address addr; addr.AnyAddress(); addr.Service(port_local); mp_sockClient->Destroy(); mp_sockServ = new wxSocketServer(addr); mp_sockServ->SetEventHandler(*this, SERVER_ID); mp_sockServ->SetNotify(wxSOCKET_CONNECTION_FLAG); mp_sockServ->Notify(true); // <- incheiat repornire mp_sockserver // -> repornim text boxurile pentru introducere ip si port + butonul de reconectare tp_clasaA->Enable(true); tp_clasaB->Enable(true); tp_clasaC->Enable(true); tp_clasaD->Enable(true); tp_port->Enable(true); bp_connect->Enable(true); // <- incheiat repornire text boxuri si butoane aferente // ->oprim text box-ul pentru input si butonul de send. tp_input->Enable(false); bp_send->Enable(false); // <- incheia oprire input si send // -> oprim butonul de disconect bp_disconnect->Enable(false); // <- incheiat oprire buton disconnect. // -> actualizam status bar. StatusBar1->SetStatusText(_("Ne-am deconectat.")); // <- incheiat actualizare status bar } void Crypted_Ip2Ip_chatFrame::onServerEvent(wxSocketEvent& event) { switch(event.GetSocketEvent()) { case wxSOCKET_CONNECTION: // caz initializare conexiune noua din exterior { tp_out->Clear(); // atribuim noua conexiune lui mp_sockClient pentru a nu creea un nou socket. mp_sockClient = (wxSocketClient*)mp_sockServ->Accept(false); mp_sockClient->SetEventHandler(*this, CONN_ID); mp_sockClient->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG); mp_sockClient->Notify(true); // luam adresa prin getPeer si o salvam in temp pentru a putea actualiza status bar-ul. wxString temp; wxIPV4address addr_temp; mp_sockClient->GetPeer(addr_temp); temp = addr_temp.IPAddress(); // actualizam status bar-ul StatusBar1->SetStatusText(_("Am acceptat conexiunea pentru: ") + temp); // oprim inputul pentru ip si port + butonul de conect. tp_clasaA->Enable(false); tp_clasaB->Enable(false); tp_clasaC->Enable(false); tp_clasaD->Enable(false); tp_port->Enable(false); bp_connect->Enable(false); // pornim inputul pentru chat (tp_input) si butonul de send. tp_input->Enable(true); bp_send->Enable(true); // pornim butonul de disconnect. bp_disconnect->Enable(true); mp_sockServ->Destroy(); break; } case wxSOCKET_LOST: { wxMessageBox(_("Conexiunea a fost pierduta sau inchisa de catre celalat utilizator.")); wxIPV4address addr; addr.AnyAddress(); addr.Service(port_local); mp_sockServ->SetEventHandler(*this, SERVER_ID); mp_sockServ->SetNotify(wxSOCKET_CONNECTION_FLAG); mp_sockServ->Notify(true); } default: { wxMessageBox(_("Eveniment server necunoscut."), _("Eroare."), wxICON_ERROR); } } } // functie chemata cand primim in eveniment al mp_sockClient void Crypted_Ip2Ip_chatFrame::onSocketInput(wxSocketEvent& event) { switch(event.GetSocketEvent()) { case wxSOCKET_INPUT: // cand primim date { wxString s; wxIPV4address addr; mp_sockClient->GetPeer(addr); s = addr.IPAddress(); wxUint32 len = 256; //mp_sockClient->Read(&len, 1); //wxChar* buf = new wxChar[len]; char* buf = new char[len]; mp_sockClient->ReadMsg(buf, len); int readed = mp_sockClient->LastCount(); buf[readed] = '\0'; tp_out->AppendText(s); tp_out->AppendText(_(": ")); tp_out->AppendText(wxString::FromAscii(buf)); tp_out->AppendText(_("\n")); delete[] buf; break; } case wxSOCKET_LOST: // conexiune pierduta { wxMessageBox(_("Conexiunea a fost pierduta, sau inchisa de utilizator.")); tp_clasaA->Enable(true); tp_clasaB->Enable(true); tp_clasaC->Enable(true); tp_clasaD->Enable(true); tp_port->Enable(true); bp_connect->Enable(true); // <- incheiat repornire text boxuri si butoane aferente // ->oprim text box-ul pentru input si butonul de send. tp_input->Enable(false); bp_send->Enable(false); // <- incheia oprire input si send // -> oprim butonul de disconect bp_disconnect->Enable(false); wxIPV4address addr; addr.AnyAddress(); addr.Service(port_local); mp_sockClient->Destroy(); mp_sockServ = new wxSocketServer(addr); mp_sockServ->SetEventHandler(*this, SERVER_ID); mp_sockServ->SetNotify(wxSOCKET_CONNECTION_FLAG); mp_sockServ->Notify(true); break; } default: { } } }
Private
[
?
]
Run code
Submit