Hello, recently I've been getting into the more complicated side of Windows Programming, and I am trying to make a TCP server. I can successfully create and connect to the server, however I'm having trouble sending data from the server to the client. I want to send a message to a client as soon as it connects. Here is my accept function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int server::acceptConn()
{
//wait for incoming connections
int clientSize = sizeof(clientHint);
client = accept(listener, (sockaddr *)&clientHint, &clientSize);
if (client == INVALID_SOCKET)
{
return error("Could not create client socket");
}
char host[NI_MAXHOST];
inet_ntop(AF_INET, &clientHint.sin_addr, host, NI_MAXHOST);
std::cout << host << " connected on port " <<
ntohs(clientHint.sin_port) << "\n";
char buf[] = "You are connected to the server";
//the below line is my problem
send(client, buf, sizeof(buf), 0);
return 0;
}
putty has worked great for around 30 years or more. I suspect it is not the problem, possibly a configuration issue. If you decide you need it to work (being one of the most popular terminal programs out there) its probably something very simple to fix. If not, no harm done.