androidsocketsandroid-networkingandroid-1.6-donut

how to pass some data as a parameter like http parameter in socket?


I'm using Android 1.6. In my office there is some application which sends some data via HTTP post method.

I want to add a module send the data via socket.I send the data via socket (output stream) correctly.It receives in server side (c# socket application) socket application correctly.

But in HTTP post method some data are passed as parameter. I'm not able to find any methods in socket to send the some data as parameter and some data in streams.

The following are the code which i done for send data via socket through outpustream .

               socket=new Socket(this.ipAddress,this.port_number);

            //socket.setSocketImplFactory(fac)
            Log.i(tagName, "after creating sokcet");

            os=socket.getOutputStream();
            is=socket.getInputStream();

            dos=new DataOutputStream(os);               
            Log.i(tagName, "after creating ouput streams");

            dis=new DataInputStream(is);
            Log.i(tagName, "after creating input streams");

            //dos.writeUTF(msg[i].trim());
            //dos.write(msg[i].trim().getBytes());

            //dos.writeUTF(msg[i].trim());
            dos.write(msg[i].trim().getBytes()); //data written as bytes
            //dos.writeUTF(str)
            dos.flush();

            Log.i(tagName, "after writing data to os");

            StringBuilder sbuilder=new StringBuilder();

            ///*
            int ch;
            byte bt=1;
            while((bt=(byte) dis.read())!=-1)
            {
                Log.i(tagName, "ch="+bt);
                byte temp[]=new byte[1];
                //temp[0]=(byte)ch;
                temp[0]=(byte)bt;
                String tempStr1=new String(temp);
                Log.i(tagName, "tempstr:"+tempStr1);

                sbuilder.append(tempStr1);

                Log.i(tagName, "Data fro server : "+sbuilder.toString());
                tempStr1=null;
            }
            //*/
            //byte tt[]=new byte[dis.readLine()]
            //resultStr=dis.readLine();resultStr=resultStr.trim();
            resultStr=sbuilder.toString();
            Log.i(tagName, "server res :"+resultStr);



            if(dos!=null)
            {
                try
                {
                    dos.close();
                }
                catch(Exception ex)
                {

                }
            }

            if(dis!=null)
            {
                try
                {
                    dis.close();
                }
                catch(Exception ex){}
            }
            if(socket!=null)
            {
                try
                {
                    socket.close();
                }
                catch(Exception ex)
                {

                }
            }

The above coding snippet works correctly.

But in HTTP post method the user name and password as parameter and the actual data in streams. Like that I want to send the username and password in parameter and actual in streams.


Solution


  • I find the solution.
    We cannot send the data as parameter like http parameter in socket connection.
    We can send the data only in streams.
    In server side we can write to parse the data from the streams.

    Thanks