hola
estaba haciendo un socket sencillo e windows y se conecta bien pero cuando uso send() y recv() no me aparece nada :huh: :huh:, me podrian decir que podria estar mal, llevo un tiempo sin usar C y sockets pero no creo que se me haya olvidado como hacerlo jeje, a ver si le encuentran algo mal, porque ya lo revise y no recuerdo haber olvidado algo
solo era conectarse entre sockets y mandan un "hola mundo"
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
int main()
{
WSADATA wsa;
SOCKET sock;
struct sockaddr_in cl;
int co = 0;
char buff[50];
WSAStartup(MAKEWORD(2,2), &wsa);
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
cl.sin_family = AF_INET;
cl.sin_port = htons(8889);
cl.sin_addr.s_addr = INADDR_ANY;
if(bind(sock, (struct sockaddr*)&cl, sizeof(struct sockaddr)) == -1){
}
if(listen(sock, 1) == -1){
}
co = sizeof(struct sockaddr);
if((accept(sock, (struct sockaddr*)&cl, &co)) == -1){
accept(sock, (struct sockaddr*)&cl, &co);
}
recv(sock, buff, sizeof(buff), 0);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
int main()
{
WSADATA wsa;
SOCKET fd;
struct sockaddr_in cli;
struct hostent* he;
char buff[50] = "hola mundo";
WSAStartup(MAKEWORD(2,2), &wsa);
he = gethostbyname("127.0.0.1");
if((fd=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) != 0){
}
cli.sin_family = AF_INET;
cli.sin_port = htons(8889);
cli.sin_addr = *((struct in_addr*)he->h_addr);
connect(fd, (struct sockaddr*)&cli, sizeof(struct sockaddr));
send
(fd
, buff
, strlen(buff
), 0);
return 0;
}