elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: ¿Eres usuario del foro? Ahora tienes un Bot con IA que responde preguntas. Lo puedes activar en tu Perfil


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Sockets - linux - recibir datos
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Sockets - linux - recibir datos  (Leído 2,218 veces)
d00ze13

Desconectado Desconectado

Mensajes: 78


Ver Perfil
Sockets - linux - recibir datos
« en: 14 Noviembre 2011, 19:02 pm »

Hola buenas! tengo hecho un servidor con sockets en el cual recibo texto del cliente, pero solo me deja mandar un texto, si sigo mandando mas texto desde el cliente ya no me llegan los datos.
Os dejo el codigo del servidor a ver si encontrais algo raro.

Código
  1. #include <netinet/in.h>
  2. #include <sys/socket.h>
  3. #include <sys/types.h>
  4. #include <iostream>
  5. using namespace std;
  6. int main(){
  7.  
  8.        int sockfd, new_sock,numbytes,sin_size;
  9.        char text[1024];
  10.  
  11.        struct sockaddr_in servidor={AF_INET,htons(1234),INADDR_ANY};
  12.        struct sockaddr_in cliente;
  13.  
  14.        sockfd=socket(AF_INET,SOCK_STREAM,0);
  15.        bind(sockfd,(struct sockaddr *)&servidor,sizeof(struct sockaddr));
  16.        listen(sockfd,5);
  17.  
  18.        while(1){
  19.                sin_size=sizeof(struct sockaddr_in);
  20.                if((new_sock=accept(sockfd,(struct sockaddr *)&cliente,(socklen_t*)&sin_size))==-1){
  21.                        cout<<"Error de conexion"<<endl;
  22.                        return -1;
  23.                }
  24.  
  25.  
  26.                numbytes=recv(new_sock,text,1024,0);
  27.                text[numbytes]='\0';
  28.  
  29.                cout<<text<<endl;
  30.  
  31.                close(new_sock);
  32.        }
  33. }
  34.  
  35.  


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Medir inclinacion y recibir datos en la PC
Electrónica
loelc 4 5,478 Último mensaje 17 Enero 2007, 09:06 am
por loelc
Problema extraño al recibir string por socket TCP (ANSI-C + Berkeley sockets)
Programación C/C++
Scott Code 1 3,416 Último mensaje 6 Noviembre 2011, 20:44 pm
por Scott Code
[JSON] Recibir datos ? (solved)
PHP
Diabliyo 1 3,157 Último mensaje 6 Octubre 2012, 17:41 pm
por Diabliyo
Problema con sockets en linux
Programación C/C++
DaniekL 3 2,949 Último mensaje 6 Marzo 2013, 19:31 pm
por 0xDani
Recibir datos a través de AJAX diferentes divs
Desarrollo Web
itzg3 4 3,336 Último mensaje 10 Abril 2014, 22:36 pm
por itzg3
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines