Using SDL_net i can send message to server, but can't get answer.
My trings end on this:
Server
//SROP serv test
#include
#include
#include "SDL_net.h"
#define MAXLEN 1024
main()
{
if( SDLNet_Init()==-1 ){
printf( "SDLNet_Init(): %s\n", SDLNet_GetError() );
exit( 2 );
}
IPaddress ip,*remote_ip;
TCPsocket tcpsock,new_tcpsock;
//Get request
if( SDLNet_ResolveHost( &ip, NULL, 8080 )==-1 ){
printf( "SDLNet_ResolveHost: %s\n", SDLNet_GetError() );
exit( 1 );
}
tcpsock=SDLNet_TCP_Open( &ip );
if( !tcpsock ){
printf( "SDLNet_TCP_Open: %s\n", SDLNet_GetError() );
exit( 2 );
}
do
new_tcpsock=SDLNet_TCP_Accept( tcpsock );
while( !new_tcpsock );
char message[ MAXLEN ];
if( SDLNet_TCP_Recv( new_tcpsock, message, MAXLEN )<=0 ) printf( "Error\n" ); remote_ip=SDLNet_TCP_GetPeerAddress( new_tcpsock ); if( !remote_ip ) { printf( "SDLNet_TCP_GetPeerAddress: %s\n", SDLNet_GetError() ); printf( "This may be a server socket.\n" ); } printf( "Host: %i\nPort: %i\nMessage:\n%s\n", remote_ip->host,remote_ip->port, message );
SDLNet_TCP_Close( tcpsock );
SDLNet_Quit();
}
Client
//SROP client test
#include
#include
#include "SDL_net.h"
#define MAXLEN 1024
main()
{
if( SDLNet_Init()==-1 ){
printf( "SDLNet_Init(): %s\n", SDLNet_GetError() );
exit( 2 );
}
IPaddress ip;
TCPsocket tcpsock;
int len;
char *msg="Hello!\n";
//Sending message
if( SDLNet_ResolveHost( &ip, "127.0.0.1", 8080 )==-1 ){
printf( "SDLNet_ResolveHost: %s\n", SDLNet_GetError() );
exit( 1 );
}
tcpsock=SDLNet_TCP_Open( &ip );
if( !tcpsock ){
printf( "SDLNet_TCP_Open: %s\n", SDLNet_GetError() );
exit( 2 );
}
len=strlen( msg )+1;
if( SDLNet_TCP_Send( tcpsock, msg, len )
Now I will try to made this using http://www.alhem.net/Sockets/
No comments:
Post a Comment