#include #include #include #define WIN32_LEAN_AND_MEAN #include #include int main(int argc, char **argv) { WORD RequiredVersion; WSADATA WData; SOCKET s; struct sockaddr_in addr; long val; struct hostent *he; if (argc<4) { printf("podaj nazwe hosta, port i liczbe jako parametry\n"); return 1; } RequiredVersion = MAKEWORD(2, 0); if (WSAStartup(RequiredVersion, &WData) != 0) { printf("Blad inicjalizacji WinSock2\n"); return 1; } he = gethostbyname(argv[1]); addr.sin_family = AF_INET; addr.sin_port = htons(atoi(argv[2])); addr.sin_addr.s_addr = *((unsigned long*) he->h_addr); s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); connect(s, (struct sockaddr*) &addr, sizeof(addr)); val = atoi(argv[3]); printf("Wysylam %d do %s\n",val,inet_ntoa(addr.sin_addr)); val = htonl(val); send(s, (char*) &val, sizeof(long), 0); printf("Czekam na odpowiedz...\n"); recv(s, (char*) &val, sizeof(long), 0); val = ntohl(val); printf("Odpowiedz: %d\n", val); closesocket(s); WSACleanup(); return 0; }