Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / J2ME / IOException during HttpConnection on: 2005-04-22 07:39:35
I`ve developed a midlet to submit a score to a server and get back a response- ok, failed etc.
Below is the loop which connects to the url. It all runs fine on Nokias but throws a IOException when run
on Sony Ericsson (K700i) and Motorola (V3,V525,V500).
It seems to be thrown when the in = hc.openDataInputStream(); call is made.
When i attempt to connect, i get the screen asking whether i should allow the connection and then it fails.
Can anyone help??

I am unsure as to which hc.setRequestProperty to set. Could this be effecting it?
The url is a WAP page.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
public void run()
{
      while(running)
      {
            HttpConnection hc = null
            InputStream in = null;
            OutputStream out = null;
            StringBuffer b= new StringBuffer();
     
            try
            {
                  hc = (HttpConnection)Connector.open(url);
                  hc.setRequestMethod(HttpConnection.GET);
                  //hc.setRequestProperty(" Content-Type" ," application/x-www-form-urlencoded" );
                  //hc.setRequestProperty( " User-Agent" , agent );
                  //hc.setRequestProperty( " Content-Type" , type );
                  //hc.setRequestProperty( "Content-Length" , Integer.toString(url.length()) );

                  out = hc.openOutputStream();
                  in = hc.openDataInputStream();
                  int ch;
                  System.out.println(" Responed= " );
                  while((ch=in.read()) != -1){
                        b.append((char)ch);
                        System.out.println((char)ch);
                  }
                  doSomething(b);
            }

            catch (ConnectionNotFoundException cnfe){System.out.println(cnfe);}
            catch (IOException ie){      System.out.println(ie);}
            finally
            {
                       running=false;
                  try
                  {
                        if(in!=null) in.close();
                        if(hc!=null) hc.close();
                        if(out!=null) out.close();
                  }
                  catch(IOException ie){System.out.println(ie);}
            }
      }
}
2  Java Game APIs & Engines / J2ME / Re: recalculating png crc on: 2005-04-04 14:20:48
i'm still having trouble with certain devices. It seems to run on some of the sony ericsson's but not others.
very frustrating.
probably a platform issue.

will post it if i get it working in full.

dr_sulli
3  Java Game APIs & Engines / J2ME / Re: recalculating png crc on: 2005-03-29 08:44:47
Thanks, i'll give that a go.
dr_sulli
4  Java Game APIs & Engines / J2ME / Re: recalculating png crc on: 2005-03-29 07:39:32
I have re-read the png spec and made sure i'm not including the 4-byte length in the calculation. I've been checking the code by running the calculation on an unchanged chunk of the png and then comparing the old and new crc's, which should be the same.
The only other area i can see could be causing a problem would be when i convert the crc from an int back into 4 bytes  to be added to the newpng byte[]. The code i'm using is shown below, i don't see how this can be wrong.

thanks for the help,
dr_sulli

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
int newCrc= crc32(chunk,0,chunk.length,0xFFFFFFFF);
byte_out = new ByteArrayOutputStream ();
data_out = new DataOutputStream (byte_out);

try{
      data_out.writeInt(newCrc);
}
catch(IOException ioe){
      System.out.println("caught exception at line 846");
}
byte[] crcBytes= byte_out.toByteArray();
int blen= crcBytes.length;
for(int i=0;i<blen;i++){
      newBuffer[(bl-4)+i]=crcBytes[i];
}
try{
      im= Image.createImage(newBuffer, 0, bl);
}
catch(IllegalArgumentException iae){}            
5  Java Game APIs & Engines / J2ME / recalculating png crc on: 2005-03-23 11:53:39
Hi,
I'm currently working on a midp1 game that requires the palette of a png image to be modified and therefore requires the crc to be recalculated. When run on phones the IllegalArgumentException is thrown when the Image.createImage(byte[],int,int) method is called. I am using code taken from the png spec to recalculate the crc. I have posted it below.
Has anyone ever successfully implemented a function that achieves this sort of funcitonailty?
I would be very appreciative of any help.

Cheers,
dr_sulli

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
/**
          * Just build a plain old fashioned table based on good, old fashioned
          * values like the CRC32_POLYNOMIAL.  The table is of a fixed size.
          */

         private void buildCRCTable()
         {
            final int CRC32_POLYNOMIAL = 0xEDB88320;

            int i, j;
            int crc;

            CRCTable = new int[256];

            for (i = 0; i <= 255; i++)
            {
               crc = i;
               for (j = 8; j > 0; j--)
                  if ((crc & 1) == 1)
                     crc = (crc >>> 1) ^ CRC32_POLYNOMIAL;
                  else
                     crc >>>= 1;
               CRCTable[i] = crc;
            }
         }

 /**
          * General CRC generation function.
          *
          * @param buffer byte array to generate the CRC32
          * @param start byte start position
          * @param count number of byte's to include in CRC calculation
          * @param crc previously generated CRC32.
          *
          * @return 32 bit CRC
          */

         public int crc32(byte buffer[], int start, int count, int lastcrc)
         {
            int temp1, temp2;
            int i = start;

            int crc = lastcrc;

            while (count-- != 0)
            {
               temp1 = crc >>> 8;
               temp2 = CRCTable[(crc ^ buffer[i++]) & 0xFF];
               crc = temp1 ^ temp2;
            }

            return crc;
   }
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!