Si vous avez des informations, ou encore mieux si vous connaissez deja une lib permettant de faire ca, je suis preneur. merci
CNetwork yEp;
Datas yOp;
strcpy(yOp,"Essai de texte à envoyer....");
yEp.Connection("192.168.1.101",9999);
TCPsocket Socket= yEp.OpenTCPSocket();
yEp.SendDatas(&yOp,Socket);

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char** argv )
{
int sockfd,newsockfd,clilen,chilpid,ok,nleft,nbwriten;
char c;
char pixels[320*240];
struct sockaddr_in cli_addr,serv_addr;
if (argc!=2) {printf ("usage: socket_srv port_number\n");exit(0);}
printf ("server starting...\n");
/* ouvertture du socket */
sockfd = socket (AF_INET,SOCK_STREAM,0);
if (sockfd<0) {printf ("impossible d'ouvrir le socket\n");exit(0);}
/* initialisation des parametres */
bzero((char*) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(atoi(argv[1]));
/* effecture le bind */
if (bind(sockfd,(struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)
{printf ("impossible de faire le bind\n");exit(0);}
/* petit initialisation */
listen(sockfd,1);
/* attend la connection d'un client */
clilen = sizeof (cli_addr);
newsockfd = accept (sockfd,(struct sockaddr*) &cli_addr, &clilen);
if (newsockfd<0) {printf ("accept error\n"); exit(0);}
printf ("connection accepted\n");
printf("Attente de Q pour quitter\n");
while (1)
{
char c;
while (read(newsockfd,&c,1)!=1);
printf("%c",c);
if (c=='Q')
break;
}
close(sockfd);
printf("\n");
return 0;
}
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
// atoi
#include <string.h>
// bzero
#include <unistd.h>
#include <SDL/SDL.h>
void SetPxl(int x, int y, Uint8 color, SDL_Surface *pScreen)
{
Uint8 *bufp;
bufp = (Uint8 *)pScreen->pixels + y*pScreen->pitch + x;
*bufp = color;
SDL_UpdateRect(pScreen, x, y, 1, 1);
}
int main(int argc, char** argv )
{
int sockfd,newsockfd,clilen,chilpid,ok,nleft,nbwriten;
char c;
struct sockaddr_in cli_addr,serv_addr;
/*
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *pScreen = SDL_SetVideoMode(320,240,8,SDL_SWSURFACE);
for (int y=0;y<240;y++)
for (int x=0;x<320;x++)
SetPxl(x,y,(Uint8)x+y,pScreen);
char *pDatas = (char*)pScreen->pixels;
for (int y=0;y<240;y++)
for (int x=0;x<320;x++)
SetPxl(x,y,*++pDatas,pScreen);
printf("Taille de la SDL_Surface : %uo, %uko\n",320*240,320*240/1024);
*/
if (argc!=3) {printf ("usage socket_clt adresse_serveur numero_de_por\n");exit(0);}
printf ("client starting\n");
/* initialise la structure de donnee */
bzero((char*) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
serv_addr.sin_port = htons(atoi(argv[2]));
/* ouvre le socket */
if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
{printf("socket error\n");exit(0);}
/* effectue la connection */
if (connect(sockfd,(struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)
{printf("socket error\n");exit(0);}
// SDL_Quit();
/* repete dans le socket tout ce qu'il entend */
while (1)
{
c=getchar();
write (sockfd,&c,1);
if (c=='Q')
break;
}
printf("\n");
/* attention il s'agit d'une boucle infinie
* le socket n'est jamais ferme !
*/
return 0;
}
int done = 0;
while (done < 320*240) {
int n = write(sockfd, (char*)pDatas+done, 320*240 -done);
if (n < 0) break; /* erreur */
done += n;
}
C'est quelque chose dans ce genre là qu'il faut faire pour être sûr que tout est écrit correctement
. Faut remplacer le while(1) par while(done < 320*240). Je vais éditer ça.
int done = 0;
char pDatas[320*240];
printf("Reception de l'image en cours\n");
while (done!=320*240)
{
int n = read(sockfd, (char*)pDatas+done, 320*240 -done);
if (n < 0) break; /* erreur */
done += n;
}
if (n!=320*240)
printf("L'image n'a pas ete recue correctement\n");
else
printf("Image recu.\n");
close(sockfd);
printf("Envois de l'image en cours\n");
int done = 0;
while (done!=320*240) {
int n = write(sockfd, (char*)pDatas+done, 320*240 -done);
if (n < 0) break; /* erreur */
done += n;
}
if (done!=320*240)
printf("Echec de l'envois\n");
else
printf("Envois reussit\n");
close(sockfd);