Hey there, I have some paper work to do about a game I should be able to play with my class mates. We should be able to send and recive a struct concerning about the 'moves' of the pieces at the game. This struct is made of 4 ints, simple as that.
I had a previous paper work to do where I'd have to send ints and that was ok, but now that I have to send a struct I'm failing to do so. This is What I've tried:
1 2 3 4 5 6 7 8 9
//SERVER
struct message{
int code;
int piece;
int x;
int y;
}send;
bytes_sent=write(new_socket,&send,sizeof(message));
cout<<bytes_sent;
So far so good, I see 16 as bytes_sent's value.
On the other hand:
1 2 3 4 5 6 7 8 9
//CLIENT
struct message{
int code;
int piece;
int x;
int y;
}recive;
bytes_recvd=read(my_socket,&recive,sizeof(message));
cout<<bytes_recvd;
I always see 0 as the bytes_recvd's value.
Doing some research I found out I'd have to serialize my sending structure, but I failing to do so. Can anyone help me here? I kind of don't know what to do, would I really have to serialize? Does anyone have something for me to read or whatever? I'm lost.
And now I'm getting this error "send: Socket operation on non-socket"
I'd like to know if CAN do this "&send", as send being a struct. Because if I can, the problem could only be on the 3rd parameter, the mesage size. Right?