Currently I have a Midlet that gets text and images from a servlet using normal Http. with the code shown below. I need to replace the Servlet with a MS aspx page with underlying C# code. Can someone please provide me with C# code (or guidlines) that can do same as servlet and how can I test it on my own (single) computer. I know it is a lot to ask, but I realy am stuck especially with the testing
Many thanks
Code samples follows:
Midlet:
public Image getImage()
{
Thread t = new Thread()
{
public void run()
{
rawByte = connect();
}
};
t.run();
// ok, may it's a chance
Image img = null;
try
{
img = Image.createImage(rawByte, 0, rawByte.length);
if (img == null)
System.err.println("Failed createImage");
}
catch (Exception e)
{
// may be next time
System.err.println("Error: Load of image failed.");
}
return img;
}
private byte[] connect()
{
HttpConnection hc = null;
InputStream in = null;
byte[] raw;
String url = GameConstantsCommon.URL_CONNECT_STRING + mParams;
System.out.println(url);
try
{
hc = (HttpConnection)Connector.open(url);
in = hc.openInputStream();
int contentLength = (int)hc.getLength();
if (contentLength != -1)
{
raw = new byte[contentLength];
length = in.read(raw);
}
else
{
ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
int ch;
while ((ch = in.read()) != -1)
bStrm.write(ch);
raw = bStrm.toByteArray();
bStrm.close();
}
}
Servlet:
mProg = request.getParameter("prog");
mPar = request.getParameter("pVal");
if (mProg.equals("Image"))
{
String iconPath;
String fileName;
Image img;
iconPath = "C:/jakarta-tomcat-4.1.31/";
fileName = mPar + ".png";
File fileIn = new File(iconPath, fileName);
if (fileIn.exists())
{
try
{
// Load the image (from bytes to an Image object)
BufferedInputStream bis =
new BufferedInputStream(new FileInputStream(fileIn));
int numBytes = bis.available();
if (numBytes <= 0)
{
System.err.println(fileName + " problems");
}
else
{
byte byteData[] = new byte[numBytes];
bis.read(byteData, 0, numBytes);
bis.close();
ServletOutputStream sos = response.getOutputStream();
response.setContentType("image/png");
response.setContentLength(numBytes);
sos.write(byteData);
sos.flush();
sos.close();
bis = null;
}
}