Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Using Packet with SocketTCP  (Read 4303 times)

0 Members and 2 Guests are viewing this topic.

tobix10

  • Newbie
  • *
  • Posts: 7
    • View Profile
Using Packet with SocketTCP
« on: May 15, 2010, 05:58:51 pm »
I would like to receive emails from POP3 server. SocketTCP's function Receive can only be used with char* argument and that works, but some fields in header and text are encoded(utf-8 etc). I've read that sf::Packet could get wstring data so I tried to used it, but I have a problem.

Receive function return sf::Socket::Disconnected and object of class Packet is empty, although myPendingPacket contains all data(with sequence '.\r\n' at the end). myPendingPacketSize is -1.
I used sockets in blocking mode.

Is it a good way to get data as wide characters? If yes, why SocketTCP doesn't fill Packet object ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Using Packet with SocketTCP
« Reply #1 on: May 15, 2010, 06:39:33 pm »
SFML packets have their own protocol (they send the total size first, then the data), so you can't receive a SFML packet if the other side didn't send a SFML packet as well.

But anyway, it wouldn't help with string encodings. You can rather use the sf::Unicode stuff in the system module, or another library specialized in this kind of stuff.
Laurent Gomila - SFML developer

tobix10

  • Newbie
  • *
  • Posts: 7
    • View Profile
Using Packet with SocketTCP
« Reply #2 on: May 15, 2010, 08:15:16 pm »
Thank you, but
Can I convert UTF8 to ANSI using sf::Unicode ? Example please.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Using Packet with SocketTCP
« Reply #3 on: May 15, 2010, 08:43:56 pm »
There's no direct UTF-8 -> ANSI conversion available in SFML, but you can do it with sf::Unicode::UTF8ToUTF32 and sf::Unicode::UTF32ToANSI.
Code: [Select]
std::string utf8 = ...;

sf::Unicode::UTF32String utf32;
sf::Unicode::UTF8ToUTF32(utf8.begin(), utf8.end(), std::back_inserter(utf32));

std::string ansi;
sf::Unicode::UTF32ToANSI(utf32.begin(), utf32.end(), std::back_inserter(ansi));


If you're interested, this kind of conversion is easier in SFML 2.
Code: [Select]
std::string utf8 = ...;
sf::Utf8::ToAnsi(utf8.begin(), utf8.end(), std::back_inserter(ansi));
Laurent Gomila - SFML developer

tobix10

  • Newbie
  • *
  • Posts: 7
    • View Profile
Using Packet with SocketTCP
« Reply #4 on: May 16, 2010, 07:09:30 pm »
Unfortunately I got linker errors when using first code.
I added sfml-system-d.lib and sfml-network-d.lib to project options.
Error is caused by UTF8ToUTF32.

Quote

unresolved external symbol "private: static unsigned int const * const sf::Unicode::UTF8Offsets" (?UTF8Offsets@Unicode@sf@@0QBIB)
unresolved external symbol "private: static int const * const sf::Unicode::UTF8TrailingBytes" (?UTF8TrailingBytes@Unicode@sf@@0QBHB)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Using Packet with SocketTCP
« Reply #5 on: May 16, 2010, 07:26:51 pm »
Have you defined SFML_DYNAMIC?
Laurent Gomila - SFML developer

tobix10

  • Newbie
  • *
  • Posts: 7
    • View Profile
Using Packet with SocketTCP
« Reply #6 on: May 16, 2010, 07:46:08 pm »
No.
Now it is working :), but I'll be getting text with quoted-printable or base64 encoding. Does sfml support encoding them ?

Sorry for bothering you

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Using Packet with SocketTCP
« Reply #7 on: May 16, 2010, 08:06:52 pm »
No no, SFML doesn't handle this kind of encodings. Basically, SFML is not made for this kind of stuff (conversions between string encodings), it's implemented only for convenience and for my own internal needs.

You probably need a library which is dedicated to that, that will be better than hacking with SFML ;)
Laurent Gomila - SFML developer

tobix10

  • Newbie
  • *
  • Posts: 7
    • View Profile
Using Packet with SocketTCP
« Reply #8 on: May 16, 2010, 08:17:59 pm »
Ok, thx a lot 4 all.

 

anything