Java ME Server-Client Verbindung über Wifi

Nunu

Mitglied
Hallo an alle,

ich experimentiere gerade ein wenig mit der WLan Verbindung meines Handy(LG KF900) und habe das SDK-15 von LG installiert.

Als Beispiel Anwendung habe ich eine Server-Client Applikation geschrieben:

Im Simulator klappt alles soweit, doch wenn ich es auf das Handy lade, werde ich gefragt:
Bis zum Beenden zulassen?
Dieses Mal zulassen?
Dieses Mal ablehnen?

Wähle ich eine der ersten beiden Optionen bekomme ich eine IO Exception.

Woran könnte das liegen? Müsste nicht gefragt werden ob man über das Wi-Fi oder UMTS verbunden werden will ??


Server:
--------------------------------------------------------------------------------
Java:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;


public class MulServer {

/**
* @param args
*/
private final ServerSocket server;

public MulServer(int port) throws IOException
{
server = new ServerSocket(port);
}

private void startServing()
{
while(true)
{
Socket client = null;
try
{
client = server.accept();
handleConnection(client);
}
catch(IOException e)
{
e.printStackTrace();
}
finally{
if(client != null)
try{
client.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
}
private void handleConnection( Socket client) throws IOException
{
InputStream in = client.getInputStream();
OutputStream out= client.getOutputStream();

int factor1 = in.read();
int factor2 = in.read();

out.write(factor1 * factor2);
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

MulServer server = new MulServer( 6666);
server.startServing();
}

}
--------------------------------------------------------------------------------

Client:
--------------------------------------------------------------------------------
Java:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class Client extends MIDlet implements CommandListener{

private Command exit, start;
private Display display;
private Form form;
private TextField TF_result;


public Client() {
// TODO Auto-generated constructor stub
display = Display.getDisplay(this);
exit = new Command("Exit",Command.EXIT,1);
start = new Command("Start", Command.EXIT,1);
form = new Form("Read Write Socket");
form.addCommand(exit);
form.addCommand(start);
form.setCommandListener(this);

}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
display.setCurrent(form);
}

public void commandAction(Command command, Displayable Displayable) {
// TODO Auto-generated method stub

if(command == exit){
try {
destroyApp(false);
} catch (MIDletStateChangeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
notifyDestroyed();

}
else if(command == start){

try{
StreamConnection connection = (StreamConnection) Connector.open("socket://192.168.0.111:6666");
//PrintStream output = new PrintStream(connection.openOutputStream());
//output.println("GET /my.html HTTP/0.9\n\n");
//output.flush();
InputStream in = connection.openInputStream();
OutputStream out= connection.openOutputStream();
out.write(4);
out.write(60);
//int ch;
// while( (ch = in.read() )!= -1){
// System.out.println( (char) ch);
// }

int result = in.read();
TF_result = new TextField("Result: " + result, "", 15, TextField.ANY);
form.append(TF_result);

in.close();
//output.close();
out.close();
connection.close();


}catch( ConnectionNotFoundException error){

Alert alert = new Alert("Error", "Cannot access socket.", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}catch( IOException error){
Alert alert = new Alert("Error", error.toString(), null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
}
}

}
 

Nunu

Mitglied
Wo kriegst du diese Exception?
hast du schon mal versucht dich vorher zu verbinden?

Die Exception kommt so bald man den Start (Softbutton) drückt.


Das Handy ist bereits mit dem WLan verbunden. Denke nicht das es ein Problem mit der Verbindung ist, weil sonst würde ein ConnectionNotFoundException erscheinen. Das ist aber nicht der Fall.
 

Nunu

Mitglied
Noch mal einen prinzipielle Frage, ist das überhaupt mit dieser Connector-Klasse machbar und welche IP muss man verwenden.

Wenn ich ich jetzt das MIDlet starte, wird wieder nach dem Netzzugriff gefragt, wähle ich zb." Bis zum Beenden zulassen", stürzt das MIDlet ab ohne eine Exception. (Die Rechte sind auch richtig gesetzt).

Danke
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
M Android Server-Client-Verbindung in Android-App mit Sockets aufbauen Android & Cross-Platform Mobile Apps 5
F Server - Client Verbindung mit Java ME Android & Cross-Platform Mobile Apps 3
N Android Client-Server-Kommunikation: push oder poll? Android & Cross-Platform Mobile Apps 10
M Einfache Rechenoperation über TCP Server Android & Cross-Platform Mobile Apps 15
J Android Server-Login Daten in der App sicherer hinterlegen? Android & Cross-Platform Mobile Apps 7
M App Datenbank Server Android & Cross-Platform Mobile Apps 5
B Android TCP-Verbindung zum Server über welche Prozess auslagerung nutzen? Android & Cross-Platform Mobile Apps 1
K Android Zugriff auf FTP-Server Android & Cross-Platform Mobile Apps 1
M Android Nur erste Zeile wird vom Server empfangen Android & Cross-Platform Mobile Apps 0
L Zugriff auf entfernten mySQL-Server via Android Android & Cross-Platform Mobile Apps 4
K Android verbinden mit verschlüsselten Server Android & Cross-Platform Mobile Apps 2
M Inhalt eines Eingabefeldes an einen Server senden? Android & Cross-Platform Mobile Apps 9
T Android KontrollApp für Nitrado Server Android & Cross-Platform Mobile Apps 2
D gpx-Datei von Smartphone auf Server uploaden Android & Cross-Platform Mobile Apps 4
S Android binäre Daten zwischen Android und einem Java-Server Android & Cross-Platform Mobile Apps 5
K BT-Server EOFException abfangen Android & Cross-Platform Mobile Apps 2
M Android Von Smartphone auf Daten von Server zugreifen Android & Cross-Platform Mobile Apps 2
S Android Zugriff auf FTP Server Android & Cross-Platform Mobile Apps 7
A "HandyClient-Server-modell" Android & Cross-Platform Mobile Apps 7
D messages via xml zwischen server/clienthandy verschicken Android & Cross-Platform Mobile Apps 5
M Android TCP Client Android & Cross-Platform Mobile Apps 4
ruutaiokwu Android Selbst entwickelter SMTP-Client läuft auf PC, nicht aber auf Android Android & Cross-Platform Mobile Apps 9
M Android Simpler TLS/SSL Client Android & Cross-Platform Mobile Apps 11
R Android Mail Client öffnen Android & Cross-Platform Mobile Apps 4
Exdroid Android Broadcast client Android & Cross-Platform Mobile Apps 1
W Android HTTPS-Verbindung mit Client-Authentifizierung Android & Cross-Platform Mobile Apps 0
missy72 Kotlin SSH Verbindung mit JSch Android & Cross-Platform Mobile Apps 5
J Android VPN Verbindung herstellen? Android & Cross-Platform Mobile Apps 4
M Problem bei Werteübergabe, MSQL verbindung Android & Cross-Platform Mobile Apps 3
H WIFI, Bluetooth und NFC Verbindung überwachen Android & Cross-Platform Mobile Apps 1
H Android 3G TCP Socket Verbindung zum PC durch NAT Android & Cross-Platform Mobile Apps 8
T Android MSSQL Verbindung herstellen - Android Studio Android & Cross-Platform Mobile Apps 2
R Socket Verbindung AsycTask Android & Cross-Platform Mobile Apps 5
F Android USB Verbindung zu Windows Programm Android & Cross-Platform Mobile Apps 3
U Android Https-Verbindung Android & Cross-Platform Mobile Apps 2
K Java ME Bluetooth verbindung parameter Android & Cross-Platform Mobile Apps 3
A Problem mit HTTP- Verbindung Android & Cross-Platform Mobile Apps 4
N Handy -PC Verbindung Android & Cross-Platform Mobile Apps 2
N Blutooz-Verbindung ... ich schaffs nicht Android & Cross-Platform Mobile Apps 5
G Bluetooth Verbindung zwischen Handy und PC Android & Cross-Platform Mobile Apps 5
G Bluetooth Verbindung Android & Cross-Platform Mobile Apps 2
O Bluetooth Verbindung zwischen 2 Handys Android & Cross-Platform Mobile Apps 5
K HTTP-Verbindung mit J2ME.... Android & Cross-Platform Mobile Apps 2

Ähnliche Java Themen

Neue Themen


Oben