vc++2010 웹 서버와 클라이언트 구현
                                            
 7537 단어  필기
                    
// webserver4.cpp :              。
//
/*
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}
*/
#include "stdafx.h"
#include 
",recvBuf);
        closesocket(sockConn);
    }
}   
클라이언트
// vcHttp.cpp :              。
//
 #include   "stdafx.h"   
  #include   "winsock.h"   
  #pragma   comment(lib,"ws2_32.lib")   
  #define   winsock_version   0x0101   
int _tmain(int argc, _TCHAR* argv[])
  {   
  //I   create     C:/Inetpub/wwwroot/test/test.asp   ,start   the   web   service   
  //start   my   program,   the   result   is   OK.   
  //If   it   works,it   is   written   by   masterz,otherwise   I   don't   know   who   write   it.   
          SOCKADDR_IN   saServer;   
  LPHOSTENT   lphostent;   
  WSADATA   wsadata;   
          SOCKET   hsocket;   
  int   nRet;   
  const   char*   host_name="127.0.0.1";   
  char*   req="POST   /test/test.asp   HTTP/1.0/r/n"   
  "From:   local/r/n"   
  "User-Agent:   post_test/1.0/r/n"   
  "Content-Type:   application/x-www-form-urlencoded/r/n"   
  "Content-Length:   20/r/n/r/n"   
  "type=12345&name=aaaa";   
  if(WSAStartup(winsock_version,&wsadata))   
  printf("can't   initial   socket");   
          lphostent=gethostbyname(host_name);   
          if(lphostent==NULL)   
  printf("lphostent   is   null");   
  hsocket   =   socket(AF_INET,   SOCK_STREAM,   IPPROTO_TCP);   
          saServer.sin_family   =   AF_INET;   
  //   Use   def.   now,   need   to   handle   general   case   
  saServer.sin_port   =   htons(8888);   
  saServer.sin_addr   =   *((LPIN_ADDR)*lphostent->h_addr_list);   
          nRet   =   connect(hsocket,   (LPSOCKADDR)&saServer,   sizeof(SOCKADDR_IN));   
  if   (nRet   ==   SOCKET_ERROR)   
  {   
  printf("can't   connect");   
  closesocket(hsocket);   
  return 0;   
  }   
  else   
  printf("connected   with   %s/n",host_name);   
  nRet   =   send(hsocket,   req,   strlen(req),   0);   
  if   (nRet   ==   SOCKET_ERROR)   
  {   
  printf("send()   failed");   
  closesocket(hsocket);   
  }   
  else   
  printf("send()   OK/n");   
  char   dest[1000];   
  nRet=1;   
  while(nRet>0)   
  {   
  nRet=recv(hsocket,(LPSTR)dest,sizeof(dest),0);   
  if(nRet>0)   
  dest[nRet]=0;   
  else   
  dest[0]=0;   
  printf("/nReceived   bytes:%d/n",nRet);   
  printf("Result:/n%s",dest);   
  }   
  char a;
  a=getchar();
  }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
static 간단한 설명static 방법은 일반적으로 정적 방법이라고 부른다. 정적 방법은 어떠한 대상에 의존하지 않고 접근할 수 있기 때문에 정적 방법에 있어this는 없다. 왜냐하면 그 어떠한 대상에도 의존하지 않기 때문이다. 대상이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.