示例#1
0
int FileTransferProtocol::sendFilename(net::Socket &s, string filename) {
	int bytes_sent;
	char fNameHeader[4];
	sprintf_s(fNameHeader, "%03lu", (unsigned long)filename.size());
	bytes_sent = s.send(fNameHeader, 3, 0);
	if (bytes_sent == SOCKET_ERROR || bytes_sent != 3) {
		onTransferError("Could not send filename size");
		return -1;
	}
	bytes_sent = s.send(filename.c_str(), filename.size(), 0);
	if (bytes_sent == SOCKET_ERROR || bytes_sent != filename.size()) {
		onTransferError("Could not send filename");
		return -1;
	}
	return 0;
}
示例#2
0
int FileTransferProtocol::sendCommand(net::Socket &s, char command) {
	int bytes_sent = s.send(&command, 1, 0);
	if (bytes_sent == SOCKET_ERROR || bytes_sent != 1) {
		onTransferError("Could not send command!");
		return -1;
	}
	return 0;
}
示例#3
0
int FileTransferProtocol::sendErr(net::Socket &s) {
	char buf[3] = { 'E', 'R', 'R' };
	int bytes_sent = s.send(buf, 3, 0);
	if (bytes_sent == SOCKET_ERROR || bytes_sent != 3) {
		onTransferError("Could not send error notice to client!");
		return -1;
	}
	return 0;
}
示例#4
0
int FileTransferProtocol::sendAck(net::Socket &s) {
	char buf[3] = { 'A', 'C', 'K' };
	int bytes_sent = s.send(buf, 3, 0);
	if (bytes_sent == SOCKET_ERROR || bytes_sent != 3) {
		onTransferError("Could not acknowledge client!");
		return -1;
	}
	return 0;
}