We're giving away 10 HTC One (M8) harman/kardon edition phones for Sprint! Enter now!
Phone Scoop

printed October 1, 2014
See this page online at:

Home  ›  Forums  ›


Back to message list

Is it possible to read http:// url via socket protocol ?

by amity    May 23, 2007, 2:26 AM

package connection;

import display.Show;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.SocketConnection;
import midlet.GCFMIDlet;

public class Socket{

String url="socket://www.globallogic.com:443";
//String url="http://www.lambenttek.com:80";

SocketConnection scon=null;
HttpConnection hcon=null;

InputStream is=null;
OutputStream os=null;

DataInputStream din=null;
DataOutputStream dout=null;

StringBuffer buf= new StringBuffer();
StringBuffer header = new StringBuffer();

public Socket(GCFMIDlet midlet){


//make a connection to server
SocketConnection scon = (SocketConnection) Connector.open(url);
//System.out.println("Connection : "+scon);

// set application-specific options on the socket. Call setSocketOption to set other options
scon.setSocketOption(SocketConnection.DELAY, 1);
scon.setSocketOption(SocketConnection.KEEPALI VE,1);
scon.setSocketOption(SocketConnection.LINGER, 1);
scon.setSocketOption(SocketConnection.RCVBUF, 8000);
scon.setSocketOption(SocketConnection.SNDBUF, 8000);

// send something to server
os = scon.openOutputStream();
dout = new DataOutputStream(os);

//os.write("GET /indus_diff/index.shtml HTTP/1.1 \r\n".getBytes());

dout.writeChars("GET /indus_diff/index.shtml HTTP/1.1\n");
// dout.writeChars("User-Agent : Profile/MIDP-2.0 Configuration/CLDC-1.0\n");
// dout.writeChars("Content-Language : en-US\r\n");
// dout.writeChars("content-encoding : UTF-8\n");
// dout.writeChars("\r\n");

is = scon.openInputStream();
System.out.println("Input Stream Size : "+is.available());

// read server response
int c = 0;
while((c = is.read()) != -1) {

//storing server responce into buffer

//check the length of the buffer
System.out.println("Lenght of Buffer : "+buf.length());

//display buffer data on to a form
if(buf != null)
new Show(midlet,buf.toString()); // display on form

}catch(Exception e){



// System.out.println("finally start");
is.close(); // close streams and scon
// System.out.println("A");

// System.out.println("AB");

// System.out.println("ABC");

if(scon != null)

}catch(Exception e){
System.out.println("finally : "+e);


********************************************* *************

I am trying to read any http:// url via socket protocol but after connecting to server when I get Input Stream from connection then nothing
should me contain in it. I check the length of Input Stream via

available() method of Input stream which returns 0.

I think it not possible via Socket Connection!!!


Amit Yadav

Report to moderator


Reply You must log in to reply.

Back to message list

Subscribe to Phone Scoop News with RSS Follow @phonescoop on Twitter Phone Scoop on Facebook Phone Scoop on Google+ Subscribe to Phone Scoop on YouTube Follow on Instagram


All content Copyright 2001-2014 Phone Factor, LLC. All Rights Reserved.
Content on this site may not be copied or republished without formal permission.