[英]how to display info in a listbox instead of edit box?
i want to create a client server program in mfc i found some really good source code from this website: http://www.softwareandfinance.com/Visual_CPP/TCP_Client_Server.html 我想在MFC中创建一个客户端服务器程序,我从该网站上找到了一些非常好的源代码: http : //www.softwareandfinance.com/Visual_CPP/TCP_Client_Server.html
ok can someone help me display the information in a listbox instead of the edit box? 可以帮助我在列表框中而不是在编辑框中显示信息吗?
here's the code to process the client: 这是处理客户端的代码:
static void f(void *p)
{
CSocketTestServerDlg *pDlg = reinterpret_cast<CSocketTestServerDlg*>(p);
pDlg->ProcessClientRequest();
}
void CSocketTestServerDlg::ProcessClientRequest()
{
SOCKADDR_IN clientaddr;
struct hostent *hostentry;
int len = sizeof(clientaddr);
SOCKET clientsocket = accept(m_serversocket, (sockaddr*)&clientaddr, &len);
if(len == -1)
{
AfxMessageBox("Error accpeting the client socket");
}
else
{
char *p = inet_ntoa(clientaddr.sin_addr);
int portno = ntohs(clientaddr.sin_port);
// int inet_pton(int af, const char *restrict src, void *restrict dst);
char rbuf[1024];
recv(clientsocket, rbuf, 1024, 0);
for(int i = 1024; i >= 1; i--)
{
if(rbuf[i] == '\n' && rbuf[i - 1] == '\r')
{
rbuf[i-1] = '\0';
break;
}
}
CString strRecvData;
strRecvData.Format("%s\r\n%s %d\r\n%s\r\n\r\n", (const char*)CTime::GetCurrentTime().Format("%B %d, %Y %H:%M:%S"), p, portno, rbuf);
m_recvData += strRecvData;
m_bRefershData = true;
strcat(rbuf, "\r\n");
send(clientsocket, rbuf, 1024, 0);
closesocket(clientsocket);
}
}
so how can i just get the ip address from the client to display in a list box? 所以我怎样才能从客户端获取IP地址以显示在列表框中? i don't need all the other information 我不需要所有其他信息
Well, you already have the IP as a string in p
, don't you? 好吧,您已经在p
中将IP作为字符串了,不是吗?
You could create a CString from it to avoid UNICODE problems. 您可以从中创建一个CString以避免UNICODE问题。 Then use CListBox::AddString to output your string: 然后使用CListBox :: AddString输出您的字符串:
char *p = inet_ntoa(clientaddr.sin_addr);
CString str(p);
//CListBox listbox;
listbox.AddString(str);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.