komunikator UDP

0

Witam wszystkich . Mam problem z napisaniem komunikatora który by działał za pomocą UDP .
Tu wklejam częśc kodu napisanego przez mojego przyjaciela kompiluje się w linuxie lecz niestety w windowsie brak bibliotek , pytanie czy mozna ściągną biblioteki mające te same funkcje ( jeśli tak prossił bym o podanie nazw , najlepiej linków).

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <iostream>
#include <string>
#include <winsock.h>
using namespace std;

int main ()
{
    int sock, client;
    sockaddr_in addr, client_addr;
    socklen_t size;
    string buf;
    char buf_in[100];

    sock = socket (PF_INET, SOCK_DGRAM, 0);
    client = socket (PF_INET, SOCK_DGRAM, 0);

    memset (&addr, 0, sizeof (addr));
    memset (&client_addr, 0, sizeof (addr));
    client_addr.sin_family = PF_INET;
    addr.sin_family = PF_INET;
    addr.sin_port = htons (9000);
    addr.sin_addr.s_addr = htonl (INADDR_ANY);

    if (bind (sock, (struct sockaddr *) &addr, sizeof (struct sockaddr)))
        perror ("Funkcja bind");

    while (1)
    {
        size = sizeof (struct sockaddr);
        int r = recvfrom (sock, buf_in, 100, 0, (struct sockaddr *) &client_addr, &size);
        if (r < 0) perror ("Funkcja recvfrom");
        buf_in[r-1] = '\0';
        cout << "Odebrano od klienta " << r << " znakow: " << buf_in << endl;
        cout << "Port: " << ntohs (client_addr.sin_port) << " adres: " << inet_ntoa (client_addr.sin_addr) << endl;

        int c = sendto (sock, buf_in, r, 0, (struct sockaddr *) &client_addr, size);
        if (c < 0) perror ("Funkcja sendto");
   
        cout << "Wyslano: " << c << " znakow." << endl;
    }
    return 0;
}

Dziekuje wszystkim za odpowiedz .

0
#include <iostream>
#include <winsock.h>
#include <stdio.h>
using namespace std;

int main ()
{
    int sock, client;
    sockaddr_in addr, client_addr;
    int size;
    string buf;
    char buf_in[100];

    sock = socket (PF_INET, SOCK_DGRAM, 0);
    client = socket (PF_INET, SOCK_DGRAM, 0);

    memset (&addr, 0, sizeof (addr));
    memset (&client_addr, 0, sizeof (addr));
    client_addr.sin_family = PF_INET;
    addr.sin_family = PF_INET;
    addr.sin_port = htons (9000);
    addr.sin_addr.s_addr = htonl (INADDR_ANY);

    if (bind (sock, (struct sockaddr *) &addr, sizeof (struct sockaddr)))
        perror ("Funkcja bind");

    while (1)
    {
        size = sizeof (struct sockaddr);
        int r = recvfrom (sock, buf_in, 100, 0, (struct sockaddr *) &client_addr, &size);
        if (r < 0) perror ("Funkcja recvfrom");
        buf_in[r-1] = '\0';
        cout << "Odebrano od klienta " << r << " znakow: " << buf_in << endl;
        cout << "Port: " << ntohs (client_addr.sin_port) << " adres: " << inet_ntoa (client_addr.sin_addr) << endl;

        int c = sendto (sock, buf_in, r, 0, (struct sockaddr *) &client_addr, size);
        if (c < 0) perror ("Funkcja sendto");

        cout << "Wyslano: " << c << " znakow." << endl;
    }
    return 0;
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1