No yet encrypted...
- From: Glus Xof <gtglus gmail com>
- To: gtkmm-list gnome org
- Subject: No yet encrypted...
- Date: Mon, 5 Dec 2011 09:54:40 +0100
Hi guys,
This week, I was trying to send char strings (char *) throw low level
gio sockets (Gio::Socket), not yet encrypted.
===
Note: The format of sent messages is: a zero prefixed value of string
bytes size + string value,
Given by this function...
Glib::ustring make_messages (Glib::ustring string_value, int nofzeros)
{
std::stringstream sSize;
sSize.fill('0');
sSize.width (nofzeros);
sSize << string_value.bytes();
Glib::ustring str_size = sSize.str();
return str_size+string_value;
}
===
Glib::ustring s_mess = make_messages (message, 8);
gssize size = 0;
gssize to_send = s_mess.bytes();
while (to_send > 0)
{
try
{
size = socket->send (s_mess.c_str(), to_send);
}
catch (const Gio::Error & error)
{
stop = true;
return;
}
to_send -= size;
}
(I prefer to use a Glib::ustring object instead of a std::string,
here). The problem is that at the receiving endpoint, the messages
with a multi-byte character doesn't appear (For example: Works fine
with strings like "Hello..." or "everything else" but not with
"Привет...").
gssize size = 0;
gssize to_receive = 8;
gchar longr_mess[to_receive];
try
{
size = client_socket->receive (longr_mess, to_receive);
}
catch (const Gio::Error & error)
{
return;
}
to_receive = atoi (longr_mess);
if (to_receive == 0)
return;
gchar * r_mess = g_new0 (gchar, to_receive);
try
{
size = client_socket->receive (r_mess, to_receive);
}
catch (const Gio::Error & error)
{
return false;
}
if (size == 0)
return false;
Glib::ustring mess (r_mess, size);
g_free (r_mess);
std::cout
<< Glib::ustring::compose ("# %1", mess)
<< std::endl;
What's happen, here ?
Could you help me... ?
Glus
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]