Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WIN32_WINNT 0x0501
- #include <iostream>
- #include <winsock2.h>
- #include <ws2tcpip.h>
- using namespace std;
- int main()
- {
- int s;
- int status;
- struct addrinfo hints, *p;
- struct addrinfo *servinfo; // will point to the results
- WORD wVersionRequested;
- WSADATA wsaData;
- char ipstr[INET6_ADDRSTRLEN];
- /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
- wVersionRequested = MAKEWORD(2, 0);
- status = WSAStartup(wVersionRequested, &wsaData);
- if (status != 0) {
- /* Tell the user that we could not find a usable */
- /* Winsock DLL. */
- printf("WSAStartup failed with error: %d\n", status);
- fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
- return 1;
- }
- memset(&hints, 0, sizeof hints); // make sure the struct is empty
- hints.ai_family = AF_INET; // don't care IPv4 or IPv6
- hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
- // get ready to connect
- if ((status = getaddrinfo("manuelfrw01.dyndns.org", "8000", &hints, &servinfo)) != 0) {
- fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
- WSACleanup();
- exit(1);
- }
- s=socket(AF_INET,SOCK_STREAM,0);
- if (status == INVALID_SOCKET) {
- cout << "socket: Scoket error Last Error:" << WSAGetLastError() << endl;
- }
- status = connect(s, servinfo->ai_addr, servinfo->ai_addrlen);
- if (status == SOCKET_ERROR) {
- cout << "socket: Scoket error Last Error:" << WSAGetLastError() << endl;
- }
- char buffer[10];
- strcpy(buffer, "Hallo");
- while(1) {
- status = send(s, buffer, sizeof(buffer), 0);
- if (status == SOCKET_ERROR) {
- cout << "send Error: " << WSAGetLastError() << endl;
- } else {
- cout << "Bytes Sent: " << status << endl;
- }
- Sleep(10);
- }
- cout << "done" << endl;
- WSACleanup();
- // servinfo now points to a linked list of 1 or more struct addrinfos
- // etc.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement