本文整理汇总了C++中SocketClient::sendTo方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketClient::sendTo方法的具体用法?C++ SocketClient::sendTo怎么用?C++ SocketClient::sendTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketClient
的用法示例。
在下文中一共展示了SocketClient::sendTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
SocketClient so = SocketClient("192.168.0.179");
so.sendTo("Hello from C++ 111");
so.sendTo("Hello from C++ 222");
so.~SocketClient();
/*WSAData data;
SOCKET sock;
struct sockaddr_in si_other;
const std::string address = "192.168.0.179";
int slen = sizeof(si_other);
char message[512] = "Hello World Java, I am a C++ Client Socket";
int ret = WSAStartup(MAKEWORD(2, 2), &data);
if (ret != 0) {
printf("Error WSAStartup failed: " + WSAGetLastError());
WSACleanup();
}
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock == INVALID_SOCKET) {
printf("Error opening socket: " + WSAGetLastError());
}
memset((char *)&si_other, 0, sizeof(si_other));
si_other.sin_family = AF_INET;
si_other.sin_port = htons(8881);
si_other.sin_addr.S_un.S_addr = inet_addr(address.c_str());
std::stringstream sstm;
for (int i = 0; i < 10; i++) {
sstm << "Attemp #" << i << " - Sending:" << message << "\n";
printf(sstm.str().c_str());
ret = sendto(sock, message, strlen(message), 0, (struct sockaddr *) &si_other, slen);
if (ret < 0) {
sstm << "Failed Sending:" << WSAGetLastError();
}
sstm.str("");
}
printf("\n *** End ***");
std::getchar();
exit(0);
closesocket(sock);
WSACleanup(); */
return 0;
}