diff --git a/server_src/netmsg.cpp b/server_src/netmsg.cpp index 3893020..286ca3c 100644 --- a/server_src/netmsg.cpp +++ b/server_src/netmsg.cpp @@ -64,7 +64,7 @@ int netmsg::recv(int socket, unsigned int flags) { netlen = -1; if(socktype == SOCK_DGRAM) { - std::cout << "doing recvfrom()" << std::endl; + //std::cout << "doing recvfrom()" << std::endl; if((netlen = recvfrom(socket, data.get(), buflen, @@ -75,7 +75,7 @@ int netmsg::recv(int socket, unsigned int flags) { strerror(netlen) << std::endl; } } else if(socktype == SOCK_STREAM) { - std::cout << "doing recv()" << std::endl; + //std::cout << "doing recv()" << std::endl; if((netlen = ::recv(socket, static_cast(data.get()), buflen, diff --git a/server_src/network_bytestream.cpp b/server_src/network_bytestream.cpp index 8026a0d..c4b308d 100644 --- a/server_src/network_bytestream.cpp +++ b/server_src/network_bytestream.cpp @@ -16,12 +16,12 @@ uint64_t netorder64(uint64_t *in) { } std::shared_ptr nbstream::tobuf() { - std::shared_ptr data(new unsigned char[this->buf.size()]); + unsigned char* dbuf = new unsigned char[this->buf.size()]; size_t i = 0; for(auto &e : this->buf) { - data.get()[i] = e; + dbuf[i++] = e; } - return data; + return std::shared_ptr(dbuf); } /* ========================================================================= */ @@ -95,7 +95,7 @@ double nbstream::getDouble() { /* ========================================================================= */ void nbstream::put8(uint8_t b) { - *this->cur++ = (unsigned char)b; + this->buf.push_back((unsigned char)b); } void nbstream::put16(uint16_t s) { diff --git a/server_src/sockwrap.cpp b/server_src/sockwrap.cpp index cf34dc1..4cf4c4a 100644 --- a/server_src/sockwrap.cpp +++ b/server_src/sockwrap.cpp @@ -10,7 +10,7 @@ netmsg connSocket::recv(size_t bufsz, int flags) { netmsg connSocket::recv(int flags) { netmsg out(default_buflen, SOCK_STREAM); - std::cout << "made netmsg object" << std::endl; + //std::cout << "made netmsg object" << std::endl; out.recv(fd, flags); return out; } diff --git a/server_src/test_server.cpp b/server_src/test_server.cpp index b3698eb..6e293a1 100644 --- a/server_src/test_server.cpp +++ b/server_src/test_server.cpp @@ -11,7 +11,7 @@ const int connType = SOCK_STREAM; int main() { serverSocket listenSock(serverPort, connType); - std::cout << "Listening." << std::endl; + std::cout << "Listening on " << (std::string)listenSock.getbindaddr() << std::endl; while(true) { connSocket dataSock = listenSock.waitForConnection(); @@ -20,16 +20,19 @@ int main() { std::cout << "Got connection from " << (std::string)addr << std::endl; while(true) { netmsg msg = dataSock.recv(); - std::cout << "Got data!" << std::endl; + //std::cout << "Got data!" << std::endl; nbstream data = nbstream(msg); std::string dataStr = data.getNullTermString(); - std::cout << "[data]: " << dataStr << std::endl; - + nbstream replydata; replydata.putNullTermString(dataStr); + std::cout << "[data]: " << dataStr << " (" << replydata.getbufsz() << " bytes) " << std::endl;; + + //std::cout << "Reply created." << std::endl; + netmsg reply(replydata.tobuf(), replydata.getbufsz(), SOCK_STREAM); dataSock.send(reply);