how to retrive String from DatagramPacket

Posted by sajith on Stack Overflow See other posts from Stack Overflow or by sajith
Published on 2012-04-15T05:14:09Z Indexed on 2012/04/15 5:28 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

the following code prints

[B@40545a60,[B@40545a60abc exp 

but i want to print abc,so that i can retrive the correct message from the receiving system

public class Operation {
InetAddress ip;
DatagramSocket dsock;
DatagramPacket pack1;
byte[] bin,bout;
WifyOperation(InetAddress Systemip)
{
    ip=Systemip;
    try {
        dsock=new DatagramSocket();

        } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

}

void sendbyte()
{
    String senddata="abc"+"123"; 
    bout=senddata.getBytes();
    pack1=new DatagramPacket(bout,bout.length,ip,3322);
    try {
        dsock.send(pack1);
        Log.d(pack1.getData().toString(),"abc exp");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

how i retrieve string instead of byte from the packet pack1

© Stack Overflow or respective owner

Related posts about java

Related posts about android