View: Manipulation des sockets en C et C++

  1. 11 years ago by moifort
    1. // Declaration socket
    2. WSADATA WSAData;
    3. SOCKET sock;
    4. SOCKADDR_IN sin;       
    5.  
    6. // Initialisation socket
    7. WSAStartup(MAKEWORD(2,0), &WSAData);
    8.  
    9. sin.sin_addr.s_addr= inet_addr("127.0.0.1"); // Adresse IP
    10. sin.sin_family= AF_INET;
    11. sin.sin_port= htons(4001)// Port
    12. sock = socket(AF_INET,SOCK_STREAM,0);
    13. bind(sock, (SOCKADDR *)&sin, sizeof(sin));
    14.  
    15. // Si connection etablie
    16. if (connect(sock, (SOCKADDR *)&sin, sizeof(sin)) == 0)
    17. {
    18. // Declaration socket
    19. WSADATA WSAData;
    20. SOCKET sock;
    21. SOCKADDR_IN sin;       
    22.  
    23. // Initialisation socket
    24. WSAStartup(MAKEWORD(2,0), &WSAData);
    25.  
    26. sin.sin_addr.s_addr     = inet_addr("127.0.0.1"); // Adresse IP
    27. sin.sin_family    = AF_INET;
    28. sin.sin_port        = htons(4001)// Port
    29. sock = socket(AF_INET,SOCK_STREAM,0);
    30. bind(sock, (SOCKADDR *)&sin, sizeof(sin));
    31.  
    32. // Si connection etablie
    33. if (connect(sock, (SOCKADDR *)&sin, sizeof(sin)) == 0)
    34. else
    35.  
    36. // Fin
    37. closesocket(sock);
    38. WSACleanup();
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/392"></script>

0 comment about "Manipulation des sockets en C et C++"