C++ Socket Server - Sending Data

Hello, Guys!
So I've got a Socket Server and Client set up right now.
Currently, It does listen for a connection, and if the Server is running,
The Client says so.
What I'm trying to do is simple.
Just a little test-run of sending out data to one-another.
Here is what I currently have:
1
2
char* hey = "Hello!";
send(socket,hey,4,0);

and
1
2
3
char* hey;
recv(socket,hey,4,0);
cout << "\nThe client says: " << hey;

As you can see, I have the Client send hello to the server,
In which the server respondes "Hello!".
Although this looks great, It doesn't work.
What happens is that when I connect to the server, the server does everything it should, then right after saying "The client says: " (But before saying "Hello!") the server app window freezes and asks to close it.

Which means it's not recieving properly.
If there something i'm doing wrong that I should be aware of?

I am a little drowsy on the send and recv funtions.
Here is what I understand of them:
send(Send to the socket of the server, Send the char of 'hey', bytes of data, 0);
and
recv(Recieve from the socket of the client, recieve the char of 'hey', bytes of data, 0);

Surely i'm doing something wrong. A response would be great!
In your client code you have not allocated any memory for hey so when recv tries to write to it you are writing to random memory that is probably not yours.
Okay, and how do you suggest I write to it?
This is what I did now:
1
2
char* hey = "Hello!";
send(Server, hey, sizeof(hey), 0);

And
1
2
3
4
char* hey;
recv(Client, hey, sizeof(hey), 0);
std::cout << "Bytes: " << sizeof(hey);
std::cout << "Sent Text: " << &hey;

I ended up with this on the window:
Bytes: 4
Sent Text: 0x28fd88

Hmmm?
sizeof(hey) is the size of the pointer

Do it like so:
1
2
3
4
char hey[100];
recv(Client, hey, sizeof(hey), 0);
std::cout << "Bytes: " << sizeof(hey);
std::cout << "Sent Text: " << &hey;


recv() returns the number of bytes received if any (and no error)
Topic archived. No new replies allowed.