-
Notifications
You must be signed in to change notification settings - Fork 0
/
Request.cc
39 lines (33 loc) · 1.07 KB
/
Request.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "Request.hh"
#include <errno.h>
#include <unistd.h>
#include <iostream>
using namespace std;
/*
receive request and send back socket to talk on?
*/
void Request::handleServer(int returnsckt) {
cout << "Returning message on socket: " << returnsckt << '\n';
char buf[256];
// first read incoming message from client
int bytesRead = read(returnsckt, buf, 256);
if (bytesRead < 1) perror("Read error: ");
cout << "bytes read: " << bytesRead << ' ';
for (int i = 0; i < bytesRead; i++) // dump out buffer as numbers
cout << int(buf[i]) << ' ';
cout << '\n';
// now write back to client
const char answer[] = "testing";
write(returnsckt, answer, sizeof(answer));
}
void Request::handle(int returnsckt) {
cout << "Received socket: " << returnsckt << '\n';
char buf[256];
int bytesRead = read(returnsckt, buf, 256);
if (bytesRead < 1) perror("Read error: ");
cout << "bytes read: " << bytesRead << ' ';
for (int i = 0; i < bytesRead; i++) // dump out buffer as numbers
cout << int(buf[i]) << ' ';
cout << '\n';
cout << buf << '\n';
}