控制台聊天程序服务器端代码

http://www.itjxue.com  2015-07-17 00:54  来源:未知  点击次数: 

  今天在网上找到了个控制台聊天程序实例,感觉不错,稍微做些修改,以作收藏之用。

  服务器端程序代码:

  view plaincopy to clipboardprint?

  // 2009-06-28

  #pragma comment(lib,"ws2_32.lib")

  #include

  #include

  #include

  using namespace std;

  string strCurMsg="";

  void recvProc(SOCKET sockConnect)

  {

  char msgRcv[100]={0};

  while(true)

  {

  if(SOCKET_ERROR==recv(sockConnect,msgRcv,sizeof(msgRcv),0))

  {

  cout<<"\nHe is leaving";

  return;

  }

  if(msgRcv[0]!=’\0’)

  {

  strCurMsg.erase(strCurMsg.end()-7,strCurMsg.end());

  strCurMsg+="He said: ";

  strCurMsg+=msgRcv;

  strCurMsg+=’\n’;

  strCurMsg+="input: ";

  system("cls");

  cout<

  }

  }

  }

  int main(int argc, char* argv[])

  {

  WORD wVersionRequested;

  WSADATA wsaData;

  int err;

  wVersionRequested = MAKEWORD( 1, 1 );

  err = WSAStartup( wVersionRequested, &wsaData );

  if ( err != 0 ) {

  return 1;

  }

(责任编辑:IT教学网)

更多

推荐计算机等级考试文章