1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
// Pour sockets //
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#define INVALID_SOCKET -1 // def de la valeur de defaut qu une fonction peut me renvoyer // pour la comparaison
#define SOCKET_ERROR -1
#define closesocket(s) close(s)
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
// Standard //
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <time.h>
#include <math.h>
//Port de communication output //
#define PORT 5001
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>
int main()
{
SOCKET sock; //nom de ma socket
SOCKADDR_IN sin; // adresse ip
SOCKET csock;
SOCKADDR_IN csin;
char buffer[20]; // taille du buffer dans lequel vas etre mes data
socklen_t recsize = sizeof(csin);
int sock_err;
socklen_t fromlen = sizeof(sin);
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sock != INVALID_SOCKET) // Configuration //
{
sin.sin_addr.s_addr = inet_addr("10.10.10.104");
// sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_family = AF_INET; // Protocole(TCP/IP)
sin.sin_port = htons(PORT); // Listage du port
sock_err = bind(sock, (SOCKADDR*)&sin, sizeof(sin));
if (sock_err==SOCKET_ERROR){return 0;}
else{printf("La socket est maintenant ouverte en mode UDP \n");}
}
wchar_t *chaine = L"MO=1\n";
setlocale(LC_CTYPE, "utf-8");
wprintf(L"%ls", chaine);
// char utf8[] = u8"MO=1\n";
//char * message=utf8;
int sock_errsend=sendto(sock,chaine, sizeof(chaine), 0, (SOCKADDR *)&sin, sizeof(sin));
printf("send= %d \n",sock_errsend);
//Fermeture de la socket
printf("Fermeture de la socket...\n");
closesocket(sock);
printf("Fermeture du serveur terminee\n");
} |
Partager