Hi,
I have little experience with writing to Http socket. I am trying to send data to another computer through Http protocol, just like having a chat between two application but instead of using Socket connection I want to use Http connection. The server writes to http connection data and the client receives it: text, files, etc... is this possible?

I tried to send text and integers to an URL and then read from that URL. I write something to the URL but when I read from it, it returns to sourcecode of that page :(.
Is it possible to use Http connection instead of socket connection for an application such as socket.. to transfer files and messages?

try {
            URL url = new URL("http://abcdefg.com");
            try {
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setDoOutput(true);
                DataOutputStream d = new DataOutputStream(conn.getOutputStream());

                String data = "123";

                data = URLEncoder.encode(data, "UTF-8");

                d.writeUTF(data);
                d.flush();
                d.close();
            } catch (IOException ex) {
                Logger.getLogger(chatServer.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (MalformedURLException ex) {
            Logger.getLogger(chatServer.class.getName()).log(Level.SEVERE, null, ex);
        }


////////////////////////

try {
            URL url = new URL("http://abcdefg.com");
            try {
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setDoInput(true);
                DataInputStream input = new DataInputStream(conn.getInputStream());



                System.out.println("numar = "+input.readUTF());
                input.close();
            } catch (IOException ex) {
                Logger.getLogger(chatServer.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (MalformedURLException ex) {
            Logger.getLogger(chatServer.class.getName()).log(Level.SEVERE, null, ex);
        }

Thanks for reading.

uhm,clawsy we now at another big debate...

definitely i know so far we should use TCP FOR send data from one pc to another....

http protocol it depends server to client not in the case of peer to peer...

so i also think about how do get data through http for peer to peer...

Yes... I'm just wondering if this if possible.... and if it is.. how can be done.

clawsy,i have one idea that is,

we should store the data in web and other end should read those data as update frequently...

like p1 and p2 interact with centralized web site from there they can exchange their data respectively using their session pass word...

can u understand what i come to say????????????

ok i now going to home...and come tomorrow with some ideas...

I understand but it's less performant. I need to write to the Http Socket or something like that. If you don't store it in the data buffer it's not performant....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.