Sorry for warming up an old topic. I'm going to do rather the same StingRay wanted to do. My problem is the implementation with wxSocket: I think events are in this case unpractical, because an OnInput function doesn't (and shouldn't IMO) know, what was sent to the server before. Thus I decided to use wxSocket without events in a thread, but it doesn't work. This is probably because I'm new with sockets at all and I would be very pleased if someone of you could give me a short example which for example connects to a server, receives the "welcome" string, writes the "HELO" message back and receives again the answer. That's my try:
//...get hostname and port...
wxIPV4address addr;
addr.Hostname(hostname);
addr.Service(port);
wxSocketClient* m_socket = new wxSocketClient();
m_socket->SetFlags(wxSOCKET_NONE);
m_socket->SetTimeout(10);
if(!m_socket->Connect(addr, true))
return;
m_socket->Read(buffer, 2048);
len = m_socket->LastCount();
//...print the buffer...
m_socket->Write("HELO", 5); // 5 or 4? or: with or without the termination? [EDIT]ouch. newline forgotten[/EDIT]
m_socket->Read(buffer2, 2048);
len = m_socket->LastCount(); // len it's 0 (!) but the server _must_ response, tested with telnet
//..print again...
[EDIT]How can I use events here? Would be a better style, I think[/EDIT]
Thanks.