Can you make a small simple program that compiles and executes with client and server parts to demonstrate the problem?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Sorry, I don't know anything about the Android environment.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Maybe something like...
SocketAddress addr = new InetSocketAddress("192.168.0.23", 10123);
...
Socket socket10123 = new Socket(addr);
...
public boolean ConnectToServer() {
try {
if (!Globals.socket10123.isConnected()) {
Globals.socket10123.connect (addr);
}
return Globals.socket10123.isConnected();
} catch(Exception e) {
e.printStackTrace();
return false;
}
}
... but you will still have to deal with the input/output Streams that will have closed when the connection was dropped, and any reads that were blocked waiting on an input Stream.
JamesCherrill
Posting Genius
6,372 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Opps, sorry. my mistake. Yes - just create a new Socket(), then use connect(SocketAddress) instead. (or just create a Socket() and let your ConnectToServer method do the rest - better IMHO because of less duplicated code).
JamesCherrill
Posting Genius
6,372 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
@ajst doing little of your own "homework" would have already got you there
SocketAddress addr = new InetSocketAddress("192.168.0.23", 10123);
Socket socket10123 = new Socket(addr);
just need to be written as
Socket socket10123 = new Socket(InetAddress.getByName("192.168.0.23"), 10123);
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
it was when I googled socket address java and came back with
http://download.oracle.com/javase/1.4.2/docs/api/java/net/SocketAddress.html
which explained nothing to me.
And yes if I looked into jamesCherill answer rather then just using it I would of had a better line of code like yours ;) and understand it more.
But thanks peter budo
Just make one wonder what on earth you doing in oracle documentation when you should be checking Android API
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
@ajst not to be rude but "Because Android api is based on java" is wrong answer.
1) Hibernate, Spring, JPA and other technologies are Java based and we are not using Oracle API to find specific information on classes, but rather their own APIs.
2) Android devices may use different technologies example Python , Ruby and you can also check this interesting discussion on stackoverflow - Which programming languages can I use on Android Dalvik?
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
No problem. I just want to make sure that you or someone else that may come latter would understand that even though that Android development at the moment is pre-dominantly based on Java language there are API differences and that you should check on Android API not just Java general API.
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
is this possible to coonet in that way....
maninaction
Junior Poster in Training
76 posts since Jun 2011
Reputation Points: 1
Solved Threads: 7