0 Usuarios y 1 Visitante están viendo este tema.
« anterior próximo »
Páginas: [1]
|
 |
|
Autor
|
Tema: Duda C y Sockets (Leído 411 veces)
|
|
djtuxy
|
Buenas como estan? les comento , me puse a hacer un sistema de server y cliente para conectar 2 pc y transferir archivos y quise probarlo mandando bytes y tengo un error y no se como solucionarlo, les dejo el código aver si me pueden ayudar, debo tener 400 errores asi que si encuentran otros errores diganmelo o consejos/críticas constructivas. este es el server. el cliente lo estoy haciendo. El error es: server.c:63: warning: pointer targets in passing argument 3 of ‘accept’ differ in signednessEn la linea 63, les dejo el codigo de esa parte Code (c): /*Accepting Connections*/ struct sockaddr Client; int dclient; int lclient; dclient = accept (s, &Client, &lclient);
Aca todo el source Code (c): #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <errno.h> #include <string.h> int main() { char answer; char key; char y = 'y'; printf(" .\n Welcome to the Server! .\n"); printf(".\n Do you want to turn on the server?.\n"); printf (" y/n? .\n"); fflush(stdin); scanf ("%c",&answer); if (answer == y){ /* Creating a Socket */ if (socket(AF_INET, SOCK_STREAM, 0) < 0) { printf("error %d on socketpair\n", errno); } /* Bind*/ struct sockaddr name; int s; strcpy(name.sa_data, "/tmp/sock"); s = socket(AF_UNIX, SOCK_STREAM, 0); if( s < 0) { printf("socket create failure %d\n", errno); } if (bind(s, &name, strlen(name.sa_data) + sizeof(name.sa_family)) < 0) { printf("bind failure %d\n", errno); } /* Listen */ if(listen(s, 1) < 0) { printf ("listen error %d\n", errno); } /*Accepting Connections*/ struct sockaddr Client; int dclient; int lclient; dclient = accept (s, &Client, &lclient); if (dclient < 0) { printf ("Accept error %d\n", errno); }else{ printf (".\n Now You are connected with the Client! .\n"); } /* Send & Rcv*/ char buf[256]; char recvbuf[256]; printf (" Do you want to send a file? .\n"); printf (" y/n? .\n"); fflush (stdin); scanf ("%c",&key); if( key == 'y') { if(send(s, &buf, sizeof(&buf),0) < 0) { printf ("Send error %d\n", errno); } } if( recv(dclient, &recvbuf, strlen(recvbuf),0) < 0) { printf ("Reciving error %d\n", errno); }else{ printf ("You recive a file .\n"); } } }
Gracias, y saludoss
|
|
|
|
« Última modificación: Julio 01, 2010, 16:30:34 por djtuxy »
|
En línea
|
www.area403.com.ar <---------- Nuevo diseño , MAs innovador!! Mas contenidoo!! nuevos ADMS!!
|
|
|
|
snf
|
El tercer argumento del accept difiere en el tipo de int. Vos estas usando uno con signo y te pide uno sin signo, se arregla definiendo lclient como unsigned int. Igualmente es un warning, si lo estas compilando con -Wall no hagas eso, solamente agrega warnings que se podrian ignorar tranquilamente.
|
|
|
|
|
En línea
|
|
|
|
|
djtuxy
|
Muchas graias snf, tiene muchos errores el code, asi que seguro despues me saltan las dudas
abrazo
|
|
|
|
|
En línea
|
www.area403.com.ar <---------- Nuevo diseño , MAs innovador!! Mas contenidoo!! nuevos ADMS!!
|
|
|
|
 |