AnsweredAssumed Answered

The Spark Client is not responding !!

Question asked by rajat965ng on Jun 5, 2013

My Code:

 

 

public class Communicate {

 

   

   

    public static String sendData(String str, Socket s, DataOutputStream dos)

    {

 

        byte[] buff = new byte[1024];

        try

        {

           

            System.out.println("Client Send--> "+str);

            dos.write(str.getBytes());

            BufferedInputStream bis = new BufferedInputStream(s.getInputStream());

            bis.read(buff);

           

           

           

            System.out.println("Server Send--> "+new String(buff).trim());

           

           

        }catch (Exception e) {

            // TODO: handle exception

       

           

           

        }

        return new String(buff).trim();

    }

   

 

    public static void main(String args[])

    {

            try

            {

                String recieve = "";

                Socket s = new Socket("localhost",5222);

                DataOutputStream dos = new DataOutputStream(s.getOutputStream());

                DataInputStream dis = new DataInputStream(s.getInputStream());

               

                String str1 ="<stream:stream to='localhost' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'/>";

               

                    //"<stream:stream       to='localhost'       xmlns='jabber:client'       xmlns:stream='http://etherx.jabber.org/streams'       version='1.0'>";

                    //"<stream:stream to='localhost' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>";

               

               

                recieve = sendData(str1, s, dos);

           

                String msg = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>";

                byte[] auth_msg = ("rajat" + "@" + "localhost" + "\0" + "rajat" + "\0" + "rajat").getBytes();

                msg = msg + Base64.encodeBase64String(auth_msg) + "</auth>";

               

                sendData(msg, s, dos);

               

                msg = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='" + "localhost" + "' version='1.0'>";

                String temp = sendData(msg, s, dos);

                String resc = temp.substring(temp.indexOf("id=")+4,temp.indexOf("xml:lang")-2).trim();

                msg = "<iq type='set' id='res_binding'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/></iq>";

                sendData(msg, s, dos);

               

                File f = new File("/root/Desktop/checkfile/myfile.txt");

                System.out.println(f.exists());

                double size = f.length();

                long date = f.lastModified();

                Date dt = new Date(date);

               

                byte[] buff = new byte[(int)size];

                FileInputStream fis = new FileInputStream(f);

                fis.read(buff);

                String hash = Md5Crypt.md5Crypt(buff);

               

                msg = "<iq from='rajat@localhost' to='admin@localhost' id='disco1' type='get'><query xmlns='http://jabber.org/protocol/disco#info'/></iq>";

               

                sendData(msg, s, dos);

               

                msg = "<iq id='vrC08-126' to='admin@localhost/Spark 2.6.3' from='rajat@localhost/Spark 2.6.3' type='set'><si xmlns='http://jabber.org/protocol/si' id='jsi_5471441136722873260' profile='http://jabber.org/protocol/si/profile/file-transfer'><file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='"+f.getPath()+"' size='"+(int)size+"'><desc>Sending</desc></file><feature xmlns='http://jabber.org/protocol/feature-neg'><x xmlns='jabber:x:data' type='form'><field var='stream-method' type='list-multi'><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature>  </si></iq>";

               

sendData(msg, s, dos);

               

               

               

                                        

               

            }catch (Exception e) {

       

                System.out.println(e.toString());

 

               

            }

       

    }

   

   

   

}

 

 

 

Response on Console:

 

 

Client Send--> <stream:stream to='localhost' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'/>

 

Server Send--> <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="localhost" id="f8264194" xml:lang="en" version="1.0"><stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mech anism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mech anism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>

 

Client Send--> <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>cmFqYXRAbG9jYWxob3N0AHJhamF0AHJhamF0</auth>

 

Server Send--> <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>

 

Client Send--> <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='localhost' version='1.0'>

 

Server Send--> <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="localhost" id="f8264194" xml:lang="en" version="1.0"><stream:features><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>

 

Client Send--> <iq type='set' id='res_binding'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/></iq>

 

Server Send--> <iq type="result" id="res_binding" to="localhost/f8264194"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>rajat@localhost/f8264194</jid></b ind></iq>

 

true

 

Client Send--> <iq from='rajat@localhost' to='admin@localhost' id='disco1' type='get'><query xmlns='http://jabber.org/protocol/disco#info'/></iq>

 

Server Send--> <iq type="result" id="disco1" from="admin@localhost" to="rajat@localhost/f8264194"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="account" type="registered"/><identity category="pubsub" type="pep"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>

 

Client Send--> <iq id='vrC08-126' to='admin@localhost/Spark 2.6.3' from='rajat@localhost/Spark 2.6.3' type='set'><si xmlns='http://jabber.org/protocol/si' id='jsi_5471441136722873260' profile='http://jabber.org/protocol/si/profile/file-transfer'><file xmlns='http://jabber.org/protocol/si/profile/file-transfer' name='/root/Desktop/checkfile/myfile.txt' size='20'><desc>Sending</desc></file><feature xmlns='http://jabber.org/protocol/feature-neg'><x xmlns='jabber:x:data' type='form'><field var='stream-method' type='list-multi'><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature>  </si></iq>

 

"As the Spark client on the other side 'Accepts' the file transfer, Server did not sends any Acknowledgement on the console in  response---->>"

 

Please let me know , What to do !!!

Outcomes