Please help, I am stuck with this issue.
Basically I am getting a AVATAR BASED VCARD i can see that in debug mode, but ASMACK is not parsing image properly. Its just dropping the tag which contains the image value.
Logcat shows the XML being received:
DEBUG/SMACK(1336): <NICKNAME>TC</NICKNAME>
DEBUG/SMACK(1336): <PHOTO><TYPE>im
DEBUG/SMACK(1336): age/jpeg</TYPE><BINVAL>iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAACHklEQVR42u2Zv64BQRSH9xmUCrUHEAUShUqlshWJxhOIECJ0oqIQL6BTK
DEBUG/SMACK(1336): 1AKrcYDkEgkKq3/9ya/5DQnTmaxbnb2zkm+Yu1a51szs2dmrJ8vxf1+BzxutxtwK6x/LyAlSvF4PACP6/UKjMBfNR2VqBF4N6QmQgnzxN0WMQIqkXevMwLvdlqe4G63A
DEBUG/SMACK(1336): 5fLBXiuE2svoGoalmWB0WgEtOvE2ghIxVoymQSFQgEUi0VgBF4VOB6PYDqdgslkAmazGaDPicViAYLBIKBotVognU6DT5us/wToBHU2Oq7X68C2bdDtdkGn03lKu90GJ
DEBUG/SMACK(1336): Mjv3+/3QTweB+fzGagGBd5E9RfgiUpfqNVqYLVaAacTlNPpBKQYDocgHA4D/gBVL1D9BaQTXKharYL5fA5IjP+ldKyaMvJye7PZgEAgAKR8uJj+AqpijIKa0HK5BE6HO
DEBUG/SMACK(1336): UmQx3g8BpFIBPDrxFJFewFVUUY3ajQagDoxF3e6TMK/V6lUQCwWA7zslvLxj4DTKV65XAaJRAJQcZbL5UA+nwd0nM1mwWAwADwhuq5UKgFJkI6lpqe/wKsLVNvtFhwOB
DEBUG/SMACK(1336): 7Df759CL7BQKAQoMpkMaDabgIT4g5R+n1/nXwG3IhqNglQqBXq9HvD8/oB2AryT0XBIk/r1eg08u6yirYCqFPnWgpYRkMpd1YvRs5t82grwxKmo+/bGhhF4VcyzGxy+E
DEBUG/SMACK(1336): aDhUhpWnU5djYBbGxtuD5e+FfgFV75bC/jUS/sAAAAASUVORK5CYII=</BINVAL></PHOTO>
DEBUG/SMACK(1336): <EMAIL><HOME/><INTERNET/><PREF/><USERID>test#test.com</
DEBUG/SMACK(1336): USERID>
Here, outputting the packet in my message listener, you can see that the photo tag is dropped. I don't know why asmack doesn't show this.
class MyPacketListener implements PacketListener{
public void processPacket(Packet packet){
System.out.println("IQ Received XML : " + packet);
Log.i("Packet IQ", packet.toString());
}
}
Here is the logcat output:
INFO/System.out(1336): <NICKNAME>TC</NICKNAME>
INFO/System.out(1336): <TITLE></TITLE>
INFO/System.out(1336): <EMAIL><HOME/><INTERNET/><PREF/><USERID>test#test.com</USERID>
In org/jivesoftware/smackx/provider/VCardProvider.java, circa line 117, there is this line:
vCard.setEncodedImage(getTagContents("BINVAL"));
which is incorrect. BINVAL is a child of PHOTO, not of vCard. Therefore, the image is getting set to NULL.
Related
Can anyone please help me with this code , what is the use of "boost::asio::async_write" function here
Does it sends acknowledgment back to the client ?
void handle_read(const boost::system::error_code& error,
size_t bytes_transferred)
{
if (!error)
{
boost::asio::async_write(socket_,
boost::asio::buffer(data_, bytes_transferred),
boost::bind(&session::handle_write, this,
boost::asio::placeholders::error));
}
else
{
delete this;
}
}
It looks like this is from an "echo server" example. async_write writes the contents of boost::asio::buffer(data_, bytes_transferred) to the socket.
Since we're inside handle_read we can guess that this function itself is the completion handler for a likely async_read call that filled that data_ buffer. Since we use the exact number of bytes reported back by async_read (bytes_transferred) and there's no visible manipulation on data_, we can assume that this simply sends the exact message (or data in general) received to socket_. If socket_ was also the endpoint in the async_read this is the definition of an echo server.
I'm trying to send a Message with Type.headline
This is my code:
public boolean sendText(Chat chat, String text) {
Message message = new Message();
message.setBody(text);
message.setType(Message.Type.headline);
message.setPacketID("id123456");
try {
chat.sendMessage(message);
Log.d("TAG", message.toXML().toString());
return true;
} catch (SmackException.NotConnectedException e) {}
return false;
}
But the XML that is sent, looks like this:
<message id='id123456' to='roee#192.168.0.3' type='chat'>
<body>test message</body>
<thread>ed108b04-4488-423a-a441-ca95284db6c1</thread>
</message>
As you can see, in the XML type='chat' instead of type='headline'.
Why is that and how do I change it?
Because you use a Chat to send the message.
Simply use XMPPConnection.sendStanza(Stanza) (use sendPacket(Stanza) in older Smack versions) to send you message with type headline.
I am coding a very simple program to send CERT query and receive response from a DNS by UDP and using wireshark for debugging. I send the query as an hex string and receive response from the same socket but, even I can see the complete string (response) in wireshark, the response printed by my program is truncated. Can anyone explain to me what exactly happen when receiving a response?. I measure the response is the same query I sent!. Please give an advice, something is wrong in my code and do not know how a response should be caught. Thanks.
char recv_buffer[4096]; //to allocate the response
//sending query and receiving response
to = sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *) &sock_addr, sizeof(sock_addr));
printf("sent %d bytes to 140.113.216.171\n", to);
int len = sizeof(recv_buffer);
bzero(&recv_buffer, len); //filling with 0 the recv_buffer
from = recvfrom(sock, recv_buffer, len, 0, NULL, NULL);
printf("received %d bytes from 140.113.216.171\n", from);
//Printing the string received
for(int c=0;c<from;c++){
printf("%c",recv_buffer[c]);
}
//Printing the string received
for(int c=0;c<to;c++){
you probably meant from not to here, since you want to have the number of bytes received, not sent.
I'm using SmartGWT with RestDataSource. Whenever I lose internet connection, I get an SC.warn window with:
Server returned TRANSPORT_ERROR with no error message
I have tried to intercept this message to create a more friendly message, by adding a Callback handler for RPCManager like so:
RPCManager.setHandleTransportErrorCallback(new HandleTransportErrorCallback() {
public void handleTransportError(int transactionNum, int status,
int httpResponseCode, String httpResponseText) {
System.err.println("Transaction number: "+transactionNum);
System.err.println("Status: "+status);
System.err.println("Response code: "+httpResponseCode);
System.err.println("Response text:"+httpResponseText);
SC.warn("You have no internet connection.");
}
});
However, the Error messages print, and my warn message shows, but so does the system warn message above!
Keep in mind that I'm using a RestDataSource and not directly connecting to server with RPCManager.
How can I intercept this error message?
Thanks
Try instead RPCManager.setHandleErrorCallback(..).
I am implementing a server that sends xml to clients using boost. The problem I am facing is that the buffer doesn't get sent immediately and accumulates to a point then sends the whole thing. This cause a problem on my client side, when it parses the xml, it may have incomplete xml tag (incomplete message). Is there a way in boost to flush out the socket whenever it needs to send out a message? Below is server's write code.
void
ClientConnection::handle_write(const boost::system::error_code& error)
{
if (!error)
{
m_push_message_queue.pop_front ();
if (!m_push_message_queue.empty () && !m_disconnected)
{
boost::asio::async_write(m_socket,
boost::asio::buffer(m_push_message_queue.front().data(),
m_push_message_queue.front().length()),
boost::bind(&ClientConnection::handle_write, this,
boost::asio::placeholders::error));
}
}
else
{
std::err << "Error writting out message...\n";
m_disconnected = true;
m_server->DisconnectedClient (this);
}
}
Typically when creating applications using TCP byte streams the sender sends a fixed length header so the receiver knows how many bytes to expect. Then the receiver reads that many bytes and parses the resulting buffer into an XML object.
I assume you are using TCP connection. TCP is stream type, so you can't assume your packet will come in one big packet. You need to fix your communication design, by sending size length first like San Miller answer, or sending flag or delimiter after all xml data has been sent.
Assuming you are definitely going to have some data on the socket you want to clear, you could do something like this:
void fulsh_socket()
{
boost::asio::streambuf b;
boost::asio::streambuf::mutable_buffers_type bufs = b.prepare(BUFFER_SIZE);
std::size_t bytes = socket_.receive(bufs); // !!! This will block until some data becomes available
b.commit(bytes);
boost::asio::socket_base::bytes_readable command(true);
socket_.io_control(command);
while(command.get())
{
bufs = b.prepare(BUFFER_SIZE);
bytes = socket_.receive(bufs);
b.commit(bytes);
socket_.io_control(command); // reset for bytes pending
}
return;
}
where socket_ is a member variable.
HTH