user2123079
user2123079

Reputation: 686

UDT can't send unsigned char*

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?

Upvotes: 1

Views: 166

Answers (1)

Dav3xor
Dav3xor

Reputation: 396

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.

Upvotes: 1

Related Questions