I am trying to open input and output streams in android, but I am not sure how to do it. I already opened the socket connection in J2ME using the following on the server:
scn = (ServerSocketConnection) Connector.open("socket://:5000"); String myAddress = scn.getLocalAddress(); si.setText("My address: " + myAddress); // Wait for a connection. sc = (SocketConnection) scn.acceptAndOpen(); //Get address of socket connection String yourAddress = sc.getAddress(); si.setText("Connected to: " + yourAddress); is = sc.openInputStream(); os = sc.openOutputStream();
Now I want to put this in android, but I donβt let me open the input and output streams, and I also had to change several things that, I am sure, will work the same.
scn = (ServerSocket) Connector.open("socket://:5000"); String myAddress = scn.getLocalAddress(); Connection.setText("My address: " + myAddress); // Wait for a connection. Socket sc = scn.accept(); //Get address of socket connection String yourAddress = sc.getAddress(); Connection.setText("Connected to: " + yourAddress); is = sc.openInputStream(); os = sc.openOutputStream();
The errors I get in android are related to the connector, getLocalAddress, getAddress and openInput and OutputStreams.
I would appreciate any help with this, since it is very difficult for me to install this in android.
thanks
Edit:
I changed the Android code to this:
ServerSocket scn = new ServerSocket(5554); InetAddress myAddress = scn.getInetAddress(); Connection.setText("My address: " + myAddress); // Wait for a connection. Socket sc = scn.accept(); //Get address of socket connection InetAddress yourAddress = sc.getInetAddress(); Connection.setText("Connected to: " + yourAddress); is = sc.openInputStream(); os = sc.openOutputStream();
Which compiles, but I get an error:
is = sc.openInputStream(); os = sc.openOutputStream();
Is there any other way to open input and output streams in android?
Thanks.
source share