Hi,
I hope this isn’t way too far off topic. I know I’ve probably butchered
the code pretty bad. What I’m trying to do is create a client/server
setup, where the client connects to the server, the server sends a
message to the client, and the client sends a message back. Well I’ve
got it to where the server sends the data to the client. The problem is
sending it back the programs both segfault. Below is my (probably
poorly written) code. I tried to use the chat and chatd programs as a
reference for what I am doing.
// The server
void serverStart(void);
static TCPsocket servsock = NULL;
IPaddress serverIP;
int main(void)
{
int x;
SDLNet_Init();
serverStart();
serverSendData();
// Sclose(sockets.socket);
// Sclose(sockets.server);
/* for (x=0; x=1000; x++)
{
}*/
serverGetData(); /* receives data from client */
SDLNet_Quit();
return (0);
}
void serverStart(void) /* Starts sockets code for server */
{
char *data2;
char *data = "kewl";
TCPsocket newsock;
TCPsocket secsock;
// strncat(datas,"data",20);
//data *datas;
// strncat(data,"data",20);
printf("data = %s \n", data);
SDLNet_ResolveHost(&serverIP, NULL, 5555);
servsock = SDLNet_TCP_Open(&serverIP);
newsock = SDLNet_TCP_Accept(servsock);
SDLNet_TCP_Send(newsock,data,20);
// secsock = SDLNet_TCP_Accept(servsock);
// newsock = NULL;
SDLNet_TCP_Recv(servsock,data2,20);
printf("data 2 = %s \n", data2);
}
// The Client
void clientConnect(void);
char *hostname;
int main(int argc, char argv[])
{
/ clientCreateConnection();
clientGetData();
clientSendData(); */
hostname = argv[1];
SDLNet_Init();
clientConnect();
SDLNet_Quit();
return(0);
}
void clientConnect(void)
{
char *data;
char *data2 = “kewlness”;
TCPsocket *tcpsock;
TCPsocket *newsock;
IPaddress serverIP;
IPaddress *myip;
// IPadress ip;
// strncat(“tigger-1”,hostname,20);
SDLNet_ResolveHost(&serverIP,hostname,5555);
printf (“server: %s \n”, hostname);
/* if ( serverIP.host == INADDR_NONE ) {
termwin->AddText("Couldn't resolve hostname\n");
} */
// exit(1);
printf("data2 = %s \n", data2);
tcpsock = SDLNet_TCP_Open(&serverIP);
SDLNet_TCP_Recv(tcpsock,data,20);
// myip = SDLNet_TCP_GetPeerAddress(tcpsock);
//newsock = SDLNet_TCP_Accept(tcpsock);
//SDLNet_TCP_Send(newsock,data2,20);
printf ("data = %s \n", data);
exit(1);
}
Any help is greatly appreciated
Mike
PS sorry again, I’m really new to sockets, and this is the farthest I’ve
gotten with any of the libs I’ve tried.