www.pudn.com > udt4.rar > testclient.cpp


#ifndef WIN32
   #include 
   #include 
   #include 
   #include 
#else
   #include 
   #include 
#endif
#include 
#include 
#include "cc.h"
#include 

using namespace std;
using namespace UDT; 


#ifndef WIN32
void* recvdata(void*);
#else
DWORD WINAPI recvdata(LPVOID);
#endif 
 
int main() 
{ 
UDTSOCKET client = UDT::socket(AF_INET, SOCK_STREAM, 0); 
 
sockaddr_in serv_addr; 
serv_addr.sin_family = AF_INET; 
serv_addr.sin_port = htons(7000); 
inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr); 
 
memset(&(serv_addr.sin_zero), '\0', 8); 
 
// connect to the server, implict bind 
if (UDT::ERROR == UDT::connect(client, (sockaddr*)&serv_addr, sizeof(serv_addr))) 
{ 
  cout << "connect: " << UDT::getlasterror().getErrorMessage(); 
  return 0; 
} 
 
char* hello = "hello world!\n"; 
if (UDT::ERROR == UDT::send(client, hello, strlen(hello) + 1, 0)) 
{ 
  cout << "send: " << UDT::getlasterror().getErrorMessage(); 
  return 0; 
} 
 
UDT::close(client); 
 
return 1; 
}