本文介绍了没能听winock2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人请帮助我。

以下代码的输出是;


开始... 
:可比较......
:创建...
:绑定完成.. 。
:CAn不听...
:连接错误...
::: Cleaned :::





  void  serverFrm :: serverClick(wxCommandEvent&  event 
{
SOCKET sockh,socka;
WSADATA wsadata;
sockaddr_in sockAddr;

if (WSAStartup(MAKEWORD( 2 2 ),& wsadata)== 0
{
box-> AppendText(_( :Starting ... \ n));
}
if (LOBYTE(wsadata.wVersion)> = 2
{
box-> AppendText(_( :Compatable ... \ n));
}
sockh = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (sockh!= SOCKET_ERROR)
{
box-> AppendText(_( :Created ... \ n));
} else box-> AppendText(_( :连接错误... \ n));
sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons( 7777 );
sockAddr.sin_addr.S_un.S_addr = inet_addr( 127.0.0.1);
if (bind(sockh,(sockaddr *)(& sockAddr), sizeof ( sockAddr))!= SOCKET_ERROR)
{
box-> AppendText(_( :Binding Done ... \ n));
} else box-> AppendText(_( :绑定错误... \ n));
if (listen(sockh,SOMAXCONN)!= 0
{
box-> AppendText(_( :Listening ... \ n));
} else box-> AppendText(_( :CAn not listen ... \ n));
int siz = sizeof (sockh);
if (accept(sockh,reinterpret_cast< sockaddr *>(& sockAddr),& siz)!= SOCKET_ERROR)
{
box-> AppendText(_( :已连接... \ n));
} else box-> AppendText(_( :连接错误... \ n));
closesocket(sockh);
if (WSACleanup()== 0
box-> AppendText(_( ::: Cleaned ::: \ n));
}
解决方案



Any One Help Me Please.
Ouput of the following code is;

Starting...
 : Compatable...
 : Created...
 : Binding Done...
 :CAnnot listen...
 :Error connecting...
:::Cleaned:::



 void serverFrm::serverClick(wxCommandEvent& event)
 {
 SOCKET sockh,socka;
 WSADATA wsadata;
 sockaddr_in sockAddr;

 if(WSAStartup(MAKEWORD(2,2), &wsadata)==0)
 {
 box-> AppendText(_(" : Starting...\n"));
 }
 if(LOBYTE(wsadata.wVersion)>=2)
 {
 box-> AppendText(_(" : Compatable...\n"));
 }
      sockh=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
      if(sockh!=SOCKET_ERROR)
      {
 box-> AppendText(_(" : Created...\n"));
           }else box-> AppendText(_(" :Error connecting...\n"));
      sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons(7777);
sockAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
if(bind(sockh, (sockaddr*)(&sockAddr), sizeof(sockAddr))!=SOCKET_ERROR)
{
 box-> AppendText(_(" : Binding Done...\n"));
       }else box-> AppendText(_(" :Error binding...\n"));
      if(listen(sockh, SOMAXCONN)!=0)
      {
 box-> AppendText(_(" :Listening...\n"));
           }else box-> AppendText(_(" :CAnnot listen...\n"));
 int siz=sizeof(sockh);
 if(accept(sockh,reinterpret_cast<sockaddr*>(&sockAddr),&siz)!=SOCKET_ERROR)
           {
 box-> AppendText(_(" :Connected...\n"));
                } else box-> AppendText(_(" :Error connecting...\n"));
  closesocket(sockh);
 if(WSACleanup()==0)
 box-> AppendText(_(":::Cleaned:::\n"));
 }
解决方案



这篇关于没能听winock2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 00:40