按下connect按钮函数void CChatcDlg::OnButtonConnect()
{
CSocket sockclient;
if(!sockclient.Create())
{
int errcode=CAsyncSocket::GetLastError();
TRACE("Client socket connect error: %d\n",errcode);
if(!sockclient.Connect("202.195.194.160",1024))
{
int errcode1=CAsyncSocket::GetLastError();
TRACE("Client socket connect error: %d\n",errcode1);
sockclient.Close();
}
}
为什么Create不能创建呢?
总是执行到if语句里面?
请指点?
我已在头文件加了“afxsock.h”
{
CSocket sockclient;
if(!sockclient.Create())
{
int errcode=CAsyncSocket::GetLastError();
TRACE("Client socket connect error: %d\n",errcode);
if(!sockclient.Connect("202.195.194.160",1024))
{
int errcode1=CAsyncSocket::GetLastError();
TRACE("Client socket connect error: %d\n",errcode1);
sockclient.Close();
}
}
为什么Create不能创建呢?
总是执行到if语句里面?
请指点?
我已在头文件加了“afxsock.h”
UINT nSocketPort = 0,
int nSocketType = SOCK_STREAM,
LPCTSTR lpszSocketAddress = NULL
);Parameters
nSocketPort
A particular port to be used with the socket, or 0 if you want MFC to select a port.
nSocketType
SOCK_STREAM or SOCK_DGRAM.
lpszSocketAddress
A pointer to a string containing the network address of the connected socket, a dotted number such as "128.56.22.8".
Return Value
Nonzero if the function is successful; otherwise 0, and a specific error code can be retrieved by calling GetLastError.Res
Create then calls Bind to bind the socket to the specified address. The following socket types are supported: SOCK_STREAM Provides sequenced, reliable, two-way, connection-based byte streams. Uses Transmission Control Protocol (TCP) for the Internet address family.
SOCK_DGRAM Supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum length. Uses User Datagram Protocol (UDP) for the Internet address family. To use this option, you must not use the socket with a CArchive object.
单还是不知道怎么做
AfxSocketInit()试一下。
今天搞了半天,被你指点一下终于行了。
非常感谢,
现在帮老师做事 要用到winsocket希望以后能在问你。