Мне нужно открыть два http-соединения одновременно на устройстве j2me.Поэтому я открыл два HttpConnection в двух потоках.Но иногда одно соединение получало данные другого.Как я могу решить эту проблему?
Я тестирую приложение на Nokia N70.
Код большой.Я пытаюсь написать простой псевдокод.
http.java:
public class Http
{
public Http()
{
}
public void start(String url) {
new Thread() {
public void run() {
getHttp(url);
}
}.start();
}
private void getHttp(String url) {
InputStream is = null;
HttpConnection http=null ;
try {
http= (HttpConnection) Connector.open(url);
httpCode = http.getResponseCode();
is = http.openInputStream();
int ic;
byte[] tmp = new byte[1024];
while (!cancel && (ic = is.read(tmp, 0, 1024)) != -1) {
line.append((char) ic);
bao.write(tmp, 0, ic);
}
//httpnotify.receive(bao.toByteArray) ;
} catch (Exception e) {
}
}
}
client1:
Http http=new Http() ;
http.setNotify(self) ;
http.start("http://....") ;
client2:
Http http2=new Http() ;
http2.setNotify(self) ;
http2.start("http://....") ;