1

I use UDT library to send my data. But seems it unable to send unsigned char* data properly. On one side I send it like

int rc = UDT::sendmsg(socket, full_data, size, -1, true);

On another side I receive like:

unsigned char* data;
int size = 2500;
data = new char[size];

while (true) {
    int rc = UDT::recvmsg(sock, data, size);
    if (rc == -1) std::cout << "Error: " << UDT::getlasterror().getErrorMessage() << std::endl;
    else std::cout << "Received packet of length" << rc << std::endl;
}

On both sides send/receive count bytes are same. But data is different. When I do kind of

std::hash<unsigned char*> ptr_hash;
cout << "Hash: " << ptr_hash(data);

I've got different hashes. In UDT sources there are lines:

UDT_API int sendmsg(UDTSOCKET u, const char* buf, int len, int ttl = -1, bool inorder = false);
UDT_API int recvmsg(UDTSOCKET u, char* buf, int len);

As you can see input parameters are char* but not unsigned char* or void*. Does this means that I should send only char* or use for example base64 to encode my binary data?

user2123079
  • 656
  • 8
  • 29

1 Answers1

1

Oh, tricky... You're hashing your pointer.

see http://en.cppreference.com/w/cpp/utility/hash (under notes)

I'd recommend printing the hex value of what you're sending on both ends to confirm it's the same, and it should be. If you're sending a null terminated string, you might be missing the null. But that's probably not the case here, given you specify it's unsigned chars.

Dav3xor
  • 386
  • 2
  • 6
  • Yes, I found this, but forgot to write here. It is really sends ok. I did as u said: on both sides did hex-print of buffers and they were the same. But you first wrote correct answer =) – user2123079 Dec 02 '15 at 18:29