Bueno la idea me vino mientras miraba mis plantas de mariahachis XD.
aqui esta el code. con alto indice de fallos y errores e conseguid conectar .
creo que se cuales son los fallos intentare arreglarlo.
pero lo principal que e conseguido hacer servidor-cliente.
#include <iostream>
#include <fstream>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_net.h>
using namespace std;
SDL_Surface *screen;
SDL_Event evento;
Uint8 *tecla;
////////////////////////////////////////////////////////////
ofstream LOG("log.txt",ios::out);
ofstream ERROR("error.txt");
////////////////////////////////////////////////////////////
IPaddress ipservidor,*ipremitente,ipcliente;
TCPsocket sservidor,sremitente,scliente;
int opcion=0;
int cl=0;
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
char DATOS[512];
int main(int argc,char *argv[]){
SDL_Init(SDL_INIT_VIDEO);
SDLNet_Init();
screen=SDL_SetVideoMode(540,480,32,SDL_SWSURFACE);
SDL_WM_SetCaption("Servidor-Cliente, By Xafi ...",0);
//servidor
SDLNet_ResolveHost(&ipservidor,0,2000);
//sservidor=SDLNet_TCP_Open(&ipservidor);
//cliente
SDLNet_ResolveHost(&ipcliente,"127.0.0.1",2000);
//scliente=SDLNet_TCP_Open(&ipcliente);
while(1){
SDL_Delay(30);
tecla=SDL_GetKeyState(0);
SDL_PollEvent(&evento);
if(tecla[SDLK_ESCAPE])exit(1);
if(opcion==0){
if(tecla[SDLK_s]){
opcion=1;
cl=1;
}
if(tecla[SDLK_c]){
opcion=2;
cl=2;
}
}
//sservidor=SDLNet_TCP_Open(&ipservidor);
if(opcion==1){
if(cl==2 || cl==3)SDLNet_TCP_Close(scliente);
sservidor=SDLNet_TCP_Open(&ipservidor);
LOG << "\nCONEXIONES: \tServidor: " << SDLNet_Read32(&ipservidor.host);
while(1){
if(sremitente=SDLNet_TCP_Accept(sservidor)){
ERROR << "CONECTADO";
ipremitente=SDLNet_TCP_GetPeerAddress(sremitente);
LOG << "\nCONEXION: " << SDLNet_Read32(&ipremitente->host);
SDLNet_TCP_Recv(sremitente,DATOS,512);
break;
}
}
opcion=2;
cl=3;
}
if(opcion==2){
if(cl==1 || cl==3)SDLNet_TCP_Close(sservidor);
scliente=SDLNet_TCP_Open(&ipcliente);
SDLNet_TCP_Send(scliente,"datos",512);
SDLNet_TCP_Close(scliente);
opcion=1;
cl=3;
}
}
}