EDN Admin
Well-known member
This should be an echo connection,but the server doesnt get any data.
Server:
Header:
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // wsChatclientDlg.h : header file
<span style="color:Green; //
#pragma once
<span style="color:Green; // CwsChatclientDlg dialog
<span style="color:Blue; class CwsChatclientDlg : <span style="color:Blue; public CDialogEx
{
<span style="color:Green; // Construction
<span style="color:Blue; public:
SOCKET m_s;
SOCKADDR_IN m_addr;
CwsChatclientDlg(CWnd* pParent = NULL); <span style="color:Green; // standard constructor
<span style="color:Green; // Dialog Data
<span style="color:Blue; enum { IDD = IDD_WSCHATCLIENT_DIALOG };
<span style="color:Blue; protected:
<span style="color:Blue; virtual <span style="color:Blue; void DoDataExchange(CDataExchange* pDX); <span style="color:Green; // DDX/DDV support
<span style="color:Green; // Implementation
<span style="color:Blue; protected:
HICON m_hIcon;
<span style="color:Green; // Generated message map functions
<span style="color:Blue; virtual BOOL OnInitDialog();
afx_msg <span style="color:Blue; void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg <span style="color:Blue; void OnPaint();
afx_msg <span style="color:Blue; long OnAsyncSelect(WPARAM wParam,LPARAM lParam);
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
<span style="color:Blue; public:
afx_msg <span style="color:Blue; void OnBnClickedOk();
};
[/code]
<br/>
The cpp file:
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // wsChatclientDlg.cpp : implementation file
<span style="color:Green; //
#include <span style="color:#A31515; "stdafx.h"
#include <span style="color:#A31515; "wsChatclient.h"
#include <span style="color:#A31515; "wsChatclientDlg.h"
#include <span style="color:#A31515; "afxdialogex.h"
#ifdef _DEBUG
#define <span style="color:Blue; new DEBUG_NEW
#endif
#define WM_USER_ASYNC_SELECT (WM_USER+1)
<span style="color:Green; // CAboutDlg dialog used for App About
<span style="color:Blue; class CAboutDlg : <span style="color:Blue; public CDialogEx
{
<span style="color:Blue; public:
CAboutDlg();
<span style="color:Green; // Dialog Data
<span style="color:Blue; enum { IDD = IDD_ABOUTBOX };
<span style="color:Blue; protected:
<span style="color:Blue; virtual <span style="color:Blue; void DoDataExchange(CDataExchange* pDX); <span style="color:Green; // DDX/DDV support
<span style="color:Green; // Implementation
<span style="color:Blue; protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
<span style="color:Blue; void CAboutDlg:oDataExchange(CDataExchange* pDX)
{
CDialogEx:oDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
<span style="color:Green; // CwsChatclientDlg dialog
CwsChatclientDlg::CwsChatclientDlg(CWnd* pParent <span style="color:Green; /*=NULL*/)
: CDialogEx(CwsChatclientDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
<span style="color:Blue; void CwsChatclientDlg:oDataExchange(CDataExchange* pDX)
{
CDialogEx:oDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CwsChatclientDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_MESSAGE(WM_USER_ASYNC_SELECT,OnAsyncSelect)
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK, &CwsChatclientDlg::OnBnClickedOk)
END_MESSAGE_MAP()
<span style="color:Green; // CwsChatclientDlg message handlers
BOOL CwsChatclientDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
WORD wVersionRequested;
WSADATA wsaData;
<span style="color:Blue; int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
<span style="color:Blue; if (err != 0) {
<span style="color:Green; /* Tell the user that we could not find a usable */
<span style="color:Green; /* Winsock DLL. */
MessageBox(L<span style="color:#A31515; "Error",L<span style="color:#A31515; "Error");
}
<span style="color:Blue; else
MessageBox(L<span style="color:#A31515; "The Winsock 2.2 dll was found okayn",L<span style="color:#A31515; "Done");
<span style="color:Blue; wchar_t pszMessage[100]; <span style="color:Green; //informational message
m_s = socket(AF_INET,SOCK_DGRAM,0);
<span style="color:Blue; if(m_s == INVALID_SOCKET)
{
MessageBox(L<span style="color:#A31515; "Error at initialization of socket",L<span style="color:#A31515; "Error");
}
<span style="color:Blue; else
{
<span style="color:Green; //fill out the name this server will read data from
m_addr.sin_family = AF_INET;
m_addr.sin_port = htons(2050);
m_addr.sin_addr.s_addr = htonl(INADDR_ANY);
<span style="color:Green; //bind the name to the socket
<span style="color:Blue; if(bind(m_s, (LPSOCKADDR)&m_addr, <span style="color:Blue; sizeof(m_addr)) == SOCKET_ERROR)
{
MessageBox(L<span style="color:#A31515; "Error at socket binding",L<span style="color:#A31515; "Error");
}
<span style="color:Blue; else
{
SOCKADDR_IN addr;
<span style="color:Blue; int nAddrLen = <span style="color:Blue; sizeof(addr);
<span style="color:Blue; if(getsockname(m_s,(LPSOCKADDR)&addr,&nAddrLen) == SOCKET_ERROR)
MessageBox(L<span style="color:#A31515; "Datagram echo server could not get sockets port",L<span style="color:#A31515; "ERROR");
<span style="color:Blue; else
{
wsprintf(pszMessage,L<span style="color:#A31515; "Datagram echo server using port %d",
ntohs(addr.sin_port));
<span style="color:Blue; if(WSAAsyncSelect(m_s,m_hWnd,WM_USER_ASYNC_SELECT,
FD_READ |FD_WRITE) == SOCKET_ERROR)
MessageBox(L<span style="color:#A31515; "Datagram echo server could not do async select");
}
}}
<span style="color:Green; // Add "About..." menu item to system menu.
<span style="color:Green; // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
<span style="color:Blue; if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
<span style="color:Blue; if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
<span style="color:Green; // Set the icon for this dialog. The framework does this automatically
<span style="color:Green; // when the applications main window is not a dialog
SetIcon(m_hIcon, TRUE); <span style="color:Green; // Set big icon
SetIcon(m_hIcon, FALSE); <span style="color:Green; // Set small icon
<span style="color:Green; // TODO: Add extra initialization here
<span style="color:Blue; return TRUE; <span style="color:Green; // return TRUE unless you set the focus to a control
}
<span style="color:Blue; void CwsChatclientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
<span style="color:Blue; if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
<span style="color:Blue; else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
<span style="color:Green; // If you add a minimize button to your dialog, you will need the code below
<span style="color:Green; // to draw the icon. For MFC applications using the document/view model,
<span style="color:Green; // this is automatically done for you by the framework.
<span style="color:Blue; void CwsChatclientDlg::OnPaint()
{
<span style="color:Blue; if (IsIconic())
{
CPaintDC dc(<span style="color:Blue; this); <span style="color:Green; // device context for painting
SendMessage(WM_ICONERASEBKGND, <span style="color:Blue; reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
<span style="color:Green; // Center icon in client rectangle
<span style="color:Blue; int cxIcon = GetSystemMetrics(SM_CXICON);
<span style="color:Blue; int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
<span style="color:Blue; int x = (rect.Width() - cxIcon + 1) / 2;
<span style="color:Blue; int y = (rect.Height() - cyIcon + 1) / 2;
<span style="color:Green; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
<span style="color:Blue; else
{
CDialogEx::OnPaint();
}
}
<span style="color:Green; // The system calls this function to obtain the cursor to display while the user drags
<span style="color:Green; // the minimized window.
HCURSOR CwsChatclientDlg::OnQueryDragIcon()
{
<span style="color:Blue; return <span style="color:Blue; static_cast<HCURSOR>(m_hIcon);
}
<span style="color:Blue; long CwsChatclientDlg::OnAsyncSelect(WPARAM wParam,LPARAM lParam)
{
<span style="color:Blue; wchar_t pszMessage[100];
<span style="color:Blue; static <span style="color:Blue; wchar_t pBuf[101];
<span style="color:Blue; int nBytesRecv;
<span style="color:Blue; int nBytesSent;
<span style="color:Blue; static <span style="color:Blue; int nBytesToSend = 0;
<span style="color:Blue; int nError;
<span style="color:Blue; static SOCKADDR_IN addrFrom;
<span style="color:Blue; static <span style="color:Blue; int nAddrFromLen = <span style="color:Blue; sizeof(addrFrom);
<span style="color:Blue; static IN_ADDR inFrom;
<span style="color:Blue; if(WSAGETSELECTERROR(lParam) != 0)
{
wsprintf(pszMessage,L<span style="color:#A31515; "Datagram echo server async select got error %d",
WSAGETSELECTERROR(lParam));
MessageBox(pszMessage,L<span style="color:#A31515; "Error");
<span style="color:Blue; return 0L;
}
<span style="color:Blue; switch(WSAGETSELECTEVENT(lParam))
{
<span style="color:Blue; case FD_WRITE:
<span style="color:Blue; if(nBytesToSend != 0)
{
nBytesSent = sendto(m_s,(<span style="color:Blue; char*)pBuf,nBytesToSend,0,
(LPSOCKADDR)&addrFrom,nAddrFromLen);
<span style="color:Blue; if(nBytesSent == SOCKET_ERROR)
{
nError = WSAGetLastError();
<span style="color:Blue; if(nError != WSAEWOULDBLOCK)
{
wsprintf(pszMessage,L<span style="color:#A31515; "Error %d sending data to %s, %d",
nError,inet_ntoa(inFrom),ntohs(addrFrom.sin_port));
MessageBox(pszMessage,L<span style="color:#A31515; "Error");
nBytesToSend = 0;
PostMessage(WM_USER_ASYNC_SELECT,m_s,WSAMAKESELECTREPLY(FD_READ,0));
}
}
<span style="color:Blue; else
{
wsprintf(pszMessage,L<span style="color:#A31515; "Data sent (%s) to %s, %d",
pBuf,inet_ntoa(inFrom),ntohs(addrFrom.sin_port));
MessageBox(pszMessage,L<span style="color:#A31515; "Data Sent");
nBytesToSend = 0;
}
}
<span style="color:Blue; break;
<span style="color:Blue; case FD_READ:
<span style="color:Blue; if(nBytesToSend == 0)
{
nBytesRecv = recvfrom(m_s,(<span style="color:Blue; char*)pBuf,100,0,(LPSOCKADDR)&addrFrom,&nAddrFromLen);
<span style="color:Blue; if(nBytesRecv == SOCKET_ERROR)
{
nError = WSAGetLastError();
<span style="color:Blue; if(nError != WSAEWOULDBLOCK);
{
wsprintf(pszMessage,L<span style="color:#A31515; "Error %d receiving data", nError);
MessageBox(pszMessage,L<span style="color:#A31515; "Error");
}
}
<span style="color:Blue; else
{
memcpy(&inFrom,&addrFrom.sin_addr.s_addr,4);
nBytesToSend = nBytesRecv;
pBuf[nBytesToSend] = (<span style="color:Blue; wchar_t)L<span style="color:#A31515; "
Server:
Header:
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // wsChatclientDlg.h : header file
<span style="color:Green; //
#pragma once
<span style="color:Green; // CwsChatclientDlg dialog
<span style="color:Blue; class CwsChatclientDlg : <span style="color:Blue; public CDialogEx
{
<span style="color:Green; // Construction
<span style="color:Blue; public:
SOCKET m_s;
SOCKADDR_IN m_addr;
CwsChatclientDlg(CWnd* pParent = NULL); <span style="color:Green; // standard constructor
<span style="color:Green; // Dialog Data
<span style="color:Blue; enum { IDD = IDD_WSCHATCLIENT_DIALOG };
<span style="color:Blue; protected:
<span style="color:Blue; virtual <span style="color:Blue; void DoDataExchange(CDataExchange* pDX); <span style="color:Green; // DDX/DDV support
<span style="color:Green; // Implementation
<span style="color:Blue; protected:
HICON m_hIcon;
<span style="color:Green; // Generated message map functions
<span style="color:Blue; virtual BOOL OnInitDialog();
afx_msg <span style="color:Blue; void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg <span style="color:Blue; void OnPaint();
afx_msg <span style="color:Blue; long OnAsyncSelect(WPARAM wParam,LPARAM lParam);
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
<span style="color:Blue; public:
afx_msg <span style="color:Blue; void OnBnClickedOk();
};
[/code]
<br/>
The cpp file:
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; // wsChatclientDlg.cpp : implementation file
<span style="color:Green; //
#include <span style="color:#A31515; "stdafx.h"
#include <span style="color:#A31515; "wsChatclient.h"
#include <span style="color:#A31515; "wsChatclientDlg.h"
#include <span style="color:#A31515; "afxdialogex.h"
#ifdef _DEBUG
#define <span style="color:Blue; new DEBUG_NEW
#endif
#define WM_USER_ASYNC_SELECT (WM_USER+1)
<span style="color:Green; // CAboutDlg dialog used for App About
<span style="color:Blue; class CAboutDlg : <span style="color:Blue; public CDialogEx
{
<span style="color:Blue; public:
CAboutDlg();
<span style="color:Green; // Dialog Data
<span style="color:Blue; enum { IDD = IDD_ABOUTBOX };
<span style="color:Blue; protected:
<span style="color:Blue; virtual <span style="color:Blue; void DoDataExchange(CDataExchange* pDX); <span style="color:Green; // DDX/DDV support
<span style="color:Green; // Implementation
<span style="color:Blue; protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
<span style="color:Blue; void CAboutDlg:oDataExchange(CDataExchange* pDX)
{
CDialogEx:oDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
<span style="color:Green; // CwsChatclientDlg dialog
CwsChatclientDlg::CwsChatclientDlg(CWnd* pParent <span style="color:Green; /*=NULL*/)
: CDialogEx(CwsChatclientDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
<span style="color:Blue; void CwsChatclientDlg:oDataExchange(CDataExchange* pDX)
{
CDialogEx:oDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CwsChatclientDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_MESSAGE(WM_USER_ASYNC_SELECT,OnAsyncSelect)
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK, &CwsChatclientDlg::OnBnClickedOk)
END_MESSAGE_MAP()
<span style="color:Green; // CwsChatclientDlg message handlers
BOOL CwsChatclientDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
WORD wVersionRequested;
WSADATA wsaData;
<span style="color:Blue; int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
<span style="color:Blue; if (err != 0) {
<span style="color:Green; /* Tell the user that we could not find a usable */
<span style="color:Green; /* Winsock DLL. */
MessageBox(L<span style="color:#A31515; "Error",L<span style="color:#A31515; "Error");
}
<span style="color:Blue; else
MessageBox(L<span style="color:#A31515; "The Winsock 2.2 dll was found okayn",L<span style="color:#A31515; "Done");
<span style="color:Blue; wchar_t pszMessage[100]; <span style="color:Green; //informational message
m_s = socket(AF_INET,SOCK_DGRAM,0);
<span style="color:Blue; if(m_s == INVALID_SOCKET)
{
MessageBox(L<span style="color:#A31515; "Error at initialization of socket",L<span style="color:#A31515; "Error");
}
<span style="color:Blue; else
{
<span style="color:Green; //fill out the name this server will read data from
m_addr.sin_family = AF_INET;
m_addr.sin_port = htons(2050);
m_addr.sin_addr.s_addr = htonl(INADDR_ANY);
<span style="color:Green; //bind the name to the socket
<span style="color:Blue; if(bind(m_s, (LPSOCKADDR)&m_addr, <span style="color:Blue; sizeof(m_addr)) == SOCKET_ERROR)
{
MessageBox(L<span style="color:#A31515; "Error at socket binding",L<span style="color:#A31515; "Error");
}
<span style="color:Blue; else
{
SOCKADDR_IN addr;
<span style="color:Blue; int nAddrLen = <span style="color:Blue; sizeof(addr);
<span style="color:Blue; if(getsockname(m_s,(LPSOCKADDR)&addr,&nAddrLen) == SOCKET_ERROR)
MessageBox(L<span style="color:#A31515; "Datagram echo server could not get sockets port",L<span style="color:#A31515; "ERROR");
<span style="color:Blue; else
{
wsprintf(pszMessage,L<span style="color:#A31515; "Datagram echo server using port %d",
ntohs(addr.sin_port));
<span style="color:Blue; if(WSAAsyncSelect(m_s,m_hWnd,WM_USER_ASYNC_SELECT,
FD_READ |FD_WRITE) == SOCKET_ERROR)
MessageBox(L<span style="color:#A31515; "Datagram echo server could not do async select");
}
}}
<span style="color:Green; // Add "About..." menu item to system menu.
<span style="color:Green; // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
<span style="color:Blue; if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
<span style="color:Blue; if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
<span style="color:Green; // Set the icon for this dialog. The framework does this automatically
<span style="color:Green; // when the applications main window is not a dialog
SetIcon(m_hIcon, TRUE); <span style="color:Green; // Set big icon
SetIcon(m_hIcon, FALSE); <span style="color:Green; // Set small icon
<span style="color:Green; // TODO: Add extra initialization here
<span style="color:Blue; return TRUE; <span style="color:Green; // return TRUE unless you set the focus to a control
}
<span style="color:Blue; void CwsChatclientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
<span style="color:Blue; if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
<span style="color:Blue; else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
<span style="color:Green; // If you add a minimize button to your dialog, you will need the code below
<span style="color:Green; // to draw the icon. For MFC applications using the document/view model,
<span style="color:Green; // this is automatically done for you by the framework.
<span style="color:Blue; void CwsChatclientDlg::OnPaint()
{
<span style="color:Blue; if (IsIconic())
{
CPaintDC dc(<span style="color:Blue; this); <span style="color:Green; // device context for painting
SendMessage(WM_ICONERASEBKGND, <span style="color:Blue; reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
<span style="color:Green; // Center icon in client rectangle
<span style="color:Blue; int cxIcon = GetSystemMetrics(SM_CXICON);
<span style="color:Blue; int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
<span style="color:Blue; int x = (rect.Width() - cxIcon + 1) / 2;
<span style="color:Blue; int y = (rect.Height() - cyIcon + 1) / 2;
<span style="color:Green; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
<span style="color:Blue; else
{
CDialogEx::OnPaint();
}
}
<span style="color:Green; // The system calls this function to obtain the cursor to display while the user drags
<span style="color:Green; // the minimized window.
HCURSOR CwsChatclientDlg::OnQueryDragIcon()
{
<span style="color:Blue; return <span style="color:Blue; static_cast<HCURSOR>(m_hIcon);
}
<span style="color:Blue; long CwsChatclientDlg::OnAsyncSelect(WPARAM wParam,LPARAM lParam)
{
<span style="color:Blue; wchar_t pszMessage[100];
<span style="color:Blue; static <span style="color:Blue; wchar_t pBuf[101];
<span style="color:Blue; int nBytesRecv;
<span style="color:Blue; int nBytesSent;
<span style="color:Blue; static <span style="color:Blue; int nBytesToSend = 0;
<span style="color:Blue; int nError;
<span style="color:Blue; static SOCKADDR_IN addrFrom;
<span style="color:Blue; static <span style="color:Blue; int nAddrFromLen = <span style="color:Blue; sizeof(addrFrom);
<span style="color:Blue; static IN_ADDR inFrom;
<span style="color:Blue; if(WSAGETSELECTERROR(lParam) != 0)
{
wsprintf(pszMessage,L<span style="color:#A31515; "Datagram echo server async select got error %d",
WSAGETSELECTERROR(lParam));
MessageBox(pszMessage,L<span style="color:#A31515; "Error");
<span style="color:Blue; return 0L;
}
<span style="color:Blue; switch(WSAGETSELECTEVENT(lParam))
{
<span style="color:Blue; case FD_WRITE:
<span style="color:Blue; if(nBytesToSend != 0)
{
nBytesSent = sendto(m_s,(<span style="color:Blue; char*)pBuf,nBytesToSend,0,
(LPSOCKADDR)&addrFrom,nAddrFromLen);
<span style="color:Blue; if(nBytesSent == SOCKET_ERROR)
{
nError = WSAGetLastError();
<span style="color:Blue; if(nError != WSAEWOULDBLOCK)
{
wsprintf(pszMessage,L<span style="color:#A31515; "Error %d sending data to %s, %d",
nError,inet_ntoa(inFrom),ntohs(addrFrom.sin_port));
MessageBox(pszMessage,L<span style="color:#A31515; "Error");
nBytesToSend = 0;
PostMessage(WM_USER_ASYNC_SELECT,m_s,WSAMAKESELECTREPLY(FD_READ,0));
}
}
<span style="color:Blue; else
{
wsprintf(pszMessage,L<span style="color:#A31515; "Data sent (%s) to %s, %d",
pBuf,inet_ntoa(inFrom),ntohs(addrFrom.sin_port));
MessageBox(pszMessage,L<span style="color:#A31515; "Data Sent");
nBytesToSend = 0;
}
}
<span style="color:Blue; break;
<span style="color:Blue; case FD_READ:
<span style="color:Blue; if(nBytesToSend == 0)
{
nBytesRecv = recvfrom(m_s,(<span style="color:Blue; char*)pBuf,100,0,(LPSOCKADDR)&addrFrom,&nAddrFromLen);
<span style="color:Blue; if(nBytesRecv == SOCKET_ERROR)
{
nError = WSAGetLastError();
<span style="color:Blue; if(nError != WSAEWOULDBLOCK);
{
wsprintf(pszMessage,L<span style="color:#A31515; "Error %d receiving data", nError);
MessageBox(pszMessage,L<span style="color:#A31515; "Error");
}
}
<span style="color:Blue; else
{
memcpy(&inFrom,&addrFrom.sin_addr.s_addr,4);
nBytesToSend = nBytesRecv;
pBuf[nBytesToSend] = (<span style="color:Blue; wchar_t)L<span style="color:#A31515; "