windows sockets programming

Hi guys, first post here please let me know if ive posted in the wrong place or something and ill move it? Im just looking for some help with my program. I have a server and a client set up connecting through sockets and i have a basic message system setup where i send a message from server to client and the then the client echos that message back to server. I am trying to add to it so that i can open a command prompt session on client and then send commands from server to client and then output from client is send back to server. My current message system from server and client is below. Any help is hugely appreciated. Thanks

server message code:

// Do-while loop to send and receive data
char buf[4096];
string userInput;

do
{
// Prompt the user for some text
cout << "> ";
getline(cin, userInput);

if (userInput.size() > 0) // Make sure the user has typed in something
{
// Send the text
int sendResult = send(clientSocket, userInput.c_str(), userInput.size() + 1, 0);

if (sendResult != SOCKET_ERROR)
{
// Wait for response
ZeroMemory(buf, 4096);
int bytesReceived = recv(clientSocket, buf, 4096, 0);
if (bytesReceived > 0)
{
// Echo response to console
cout << "CLIENT> " << string(buf, 0, bytesReceived) << endl;
}
}
}

} while (userInput.size() > 0);

client message code:

// While loop: accept and echo message back to server
char buf[4096];
while (true)
{
ZeroMemory(buf, 4096);

// Wait for server to send data
int bytesReceived = recv(sock, buf, 4096, 0);
if (bytesReceived == SOCKET_ERROR)
{
cerr << "Error in recv(). Quitting" << endl;
break;
}

if (bytesReceived == 0)
{
cout << "Client disconnected " << endl;
break;
}

cout << string(buf, 0, bytesReceived) << endl;

// Echo message back to server
send(sock, buf, bytesReceived + 1, 0);

}
Please use the Code format tags to format your code.

It's conventional for the client to prompt for user input, and send requests, rather than the client code.

It's impossible to verify the correctness of the server code in particular because you haven't shown it.
Topic archived. No new replies allowed.