I've been working on a project for school , where we've been assigned the task to make Roulette game with 2 clients and a server (TCP). So i figured i'd make a void function for both the server and the client, to realize the communication ,but I met this error, and couldn't find where I messed up , if anyone knows , please let me know ! :)
Client:
void bet(int client,const int size,char message[])
{
char to_server[size];
if (recv(client,message,size,0) < 0)
{
Receive_Error obj;
throw obj;
}
std::cout << message << std::endl;
std::cin >>to_server;
if (send(client,to_server,sizeof(to_server),0) < 0)
{
Send_Error obj;
throw obj;
}
}
Server :
void bet(int client,char message[],const int size)
{
char to_client[size] = "Mire fogad ?\nColor[b/r] + Number [0-9] + Bet\n";
if (send(client,to_client,sizeof(to_client),0) < 0)
{
Send_Error obj;
throw obj;
}
if (recv(client,&message,size,0) < 0)
{
Receive_Error obj;
throw obj;
}
std::cout << message ;
}
In both parties , the "message" variable looks like this :
char* message = new char[size];
for ( not important )
{
bet(client_socket,message,size)
}
delete[] message;
size is a const int with the value of 256; P.S:The reason I tagged both C and C++ , is because it is a requirement to use the C functions (included in sys/socket.h,sys/types.h,netinet/in.h) but I mainly studied C++ , so I am trying to cut corners.