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
|
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define closesocket(param) close(param)
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
int main()
{
printf("debut\n");
SOCKET sock_client;
char buffer[30];
SOCKADDR_IN sin;
int rec;
sock_client=socket(AF_INET, SOCK_STREAM, 0);
if(sock_client != INVALID_SOCKET)
{
printf("aucun probleme dans la fonction socket\n");
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
sin.sin_family = AF_INET;
sin.sin_port = htons (65535);
sock_client=connect(sock_client, (SOCKADDR *)&sin, sizeof(sin));
if(sock_client != SOCKET_ERROR)
{
printf("aucun probleme dans la fonction connect\n");
rec = recv (sock_client, buffer, sizeof(buffer)- 1, 0);
if (rec > 0)
{
buffer[rec] = 0;
printf("%s\n",buffer);
}
}
}
closesocket(sock_client);
return EXIT_SUCCESS;
} |
le code ne fonctionne pas non plus. Le probleme viendrait aparement de la fonction connect car la commande
printf("aucun probleme dans la fonction connect\n");
n'est pas executé.
Cepandant je ne voit pas où est le probleme ...Une idée?
Je vais continuer a chercher en attendant une réponse.
PS:Je faisais aucune difference entre un sizeof et strlen avant (eh oui je suis pas un pro comme vous mais seulement un debutant)mais maintenant c'est plus clair. Merci emmanuel
Partager