M
mirton
Hi,
I have a server with selectors and a Midlet application.
I connect to the server from the midlet without any problem, but when I
turn of the Midlet device then an Exception is thrown
(java.io.IOException: An existing connection was forcibly closed by the
remote host).
--(at the bottom are the links to the files with the entire code)--
This is the stack trace of the exception:
java.io.IOException: An existing connection was forcibly closed by the
remote ho
st
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(Unknown Source)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.read(Unknown Source)
at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
at ServerThread.doRequest(ServerThread.java:76)
at ServerThread.requests(ServerThread.java:57)
at ServerThread.<init>(ServerThread.java:34)
at DBServer.main(DBServer.java:252)
This is the code part from the Midlet (the class extends Thread):
And this is the only place where the connection is created and no
matter what, it is closed after each operation.
public void run(){
try{
conn =
Connector.open("socket://"+host+":"+port,Connector.READ_WRITE );
out=new DataOutputStream(((OutputConnection)
conn).openOutputStream());
in=new DataInputStream(((InputConnection)
conn).openInputStream());
switch(action){
case CONNECT:
form.login();
conn.close();
System.out.println("CONNECT");
return;
case LOGIN:
login(form.loginTxt.getString(),form.passwordTxt.getString());
conn.close();
return;
case PAY:
pay();
conn.close();
return;
}
}
catch(Exception e) {
System.out.println("RUN THREAD: "+e);
if(e.toString().equals("javax.microedition.io.ConnectionNotFoundException:
TCP open")) form.noConnect();
}
}
And this is the code part where the exception occurs in the server:
try {
bb.clear();
reading:
System.out.println("IS CONNECTED: "+socket.isConnected());
while (true) {
---- int i = socket.read(bb);-------- (Exception)
if (i > 0) {
bb.flip();
CharBuffer cb = charset.decode(bb);
while (cb.hasRemaining()) {
char c = cb.get();
if (c == '\r' || c == '\n') break reading;
sb.append(c);
}
}
}
}
catch (Exception exx) {
System.out.println("Exception - reading from channel"+exx);
exx.printStackTrace();
}
Maybe this exception is thrown earlier but not shown, maybe because
most network operations in the server are non-blocking.
Links as text:
http://mirton.homeftp.net/ServerThread.txt
http://mirton.homeftp.net/Client.txt
http://mirton.homeftp.net/DBServer.txt -- (this class creates the
ServerThread object)
or as Java files:
http://mirton.homeftp.net/ServerThread.java
http://mirton.homeftp.net/Client.java
http://mirton.homeftp.net/DBServer.java
If the above links dont work then try the ones below...
Links as text:
http://www.pjwstk.edu.pl/~s3288/Client.txt
http://www.pjwstk.edu.pl/~s3288/ServerThread.txt
http://www.pjwstk.edu.pl/~s3288/DBServer.txt
or as Java files:
http://www.pjwstk.edu.pl/~s3288/ServerThread.java
http://www.pjwstk.edu.pl/~s3288/Client.java
http://www.pjwstk.edu.pl/~s3288/DBServer.java
Any help would be helpful..
I have a server with selectors and a Midlet application.
I connect to the server from the midlet without any problem, but when I
turn of the Midlet device then an Exception is thrown
(java.io.IOException: An existing connection was forcibly closed by the
remote host).
--(at the bottom are the links to the files with the entire code)--
This is the stack trace of the exception:
java.io.IOException: An existing connection was forcibly closed by the
remote ho
st
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(Unknown Source)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source)
at sun.nio.ch.IOUtil.read(Unknown Source)
at sun.nio.ch.SocketChannelImpl.read(Unknown Source)
at ServerThread.doRequest(ServerThread.java:76)
at ServerThread.requests(ServerThread.java:57)
at ServerThread.<init>(ServerThread.java:34)
at DBServer.main(DBServer.java:252)
This is the code part from the Midlet (the class extends Thread):
And this is the only place where the connection is created and no
matter what, it is closed after each operation.
public void run(){
try{
conn =
Connector.open("socket://"+host+":"+port,Connector.READ_WRITE );
out=new DataOutputStream(((OutputConnection)
conn).openOutputStream());
in=new DataInputStream(((InputConnection)
conn).openInputStream());
switch(action){
case CONNECT:
form.login();
conn.close();
System.out.println("CONNECT");
return;
case LOGIN:
login(form.loginTxt.getString(),form.passwordTxt.getString());
conn.close();
return;
case PAY:
pay();
conn.close();
return;
}
}
catch(Exception e) {
System.out.println("RUN THREAD: "+e);
if(e.toString().equals("javax.microedition.io.ConnectionNotFoundException:
TCP open")) form.noConnect();
}
}
And this is the code part where the exception occurs in the server:
try {
bb.clear();
reading:
System.out.println("IS CONNECTED: "+socket.isConnected());
while (true) {
---- int i = socket.read(bb);-------- (Exception)
if (i > 0) {
bb.flip();
CharBuffer cb = charset.decode(bb);
while (cb.hasRemaining()) {
char c = cb.get();
if (c == '\r' || c == '\n') break reading;
sb.append(c);
}
}
}
}
catch (Exception exx) {
System.out.println("Exception - reading from channel"+exx);
exx.printStackTrace();
}
Maybe this exception is thrown earlier but not shown, maybe because
most network operations in the server are non-blocking.
Links as text:
http://mirton.homeftp.net/ServerThread.txt
http://mirton.homeftp.net/Client.txt
http://mirton.homeftp.net/DBServer.txt -- (this class creates the
ServerThread object)
or as Java files:
http://mirton.homeftp.net/ServerThread.java
http://mirton.homeftp.net/Client.java
http://mirton.homeftp.net/DBServer.java
If the above links dont work then try the ones below...
Links as text:
http://www.pjwstk.edu.pl/~s3288/Client.txt
http://www.pjwstk.edu.pl/~s3288/ServerThread.txt
http://www.pjwstk.edu.pl/~s3288/DBServer.txt
or as Java files:
http://www.pjwstk.edu.pl/~s3288/ServerThread.java
http://www.pjwstk.edu.pl/~s3288/Client.java
http://www.pjwstk.edu.pl/~s3288/DBServer.java
Any help would be helpful..