Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #20197
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2012-12-09 12:36 -0800 |
| References | <9a8716eb-5842-45d8-b62e-193122cd863e@googlegroups.com> <ka2c97$ag8$1@dont-email.me> <27f309f0-5118-4fa8-8b26-858d19af27de@googlegroups.com> <ka2k1v$l3$1@dont-email.me> |
| Message-ID | <37e29245-591a-4325-b767-fdfe8d09a703@googlegroups.com> (permalink) |
| Subject | Re: Java (android) socket reconnection |
| From | artik <olsztyn.arti@gmail.com> |
Thank You very much! Honestly.
I started analyze Your code but it is partly to hard for me - I'm newbe in Java and it gives me error on invoking method "getWriter" in line:
Writer w = connector.getWriter()
and further exactly inside this method in line "else if( ! socket.isClosed() )". I'm going fight with this in next hours, and don't give up.
One hour ago I write my code as simple as I can and in one thread - everything to avoid problem with synchronization. Effect on the server is still the same (several connection attempts after starting server when client was waiting for it)
I apologize that I'm putting my code again (I hope in good format) instead try to adapt new one from You immediately, but I want to understand this problem.
thrd3 = new Thread(new Runnable() {
@Override
public void run() {
Socket sock = null;
BufferedWriter out = null;
while (true) {
//time to rest for system
try {
Thread.sleep(1000);
} catch (InterruptedException e2) {
Thread.currentThread().interrupt();
}
//attempt to send data
if (sock != null) {
try {
out.write("TEST DATA\n");
out.flush();
} catch (IOException e) {
//catch the error
// ERROR-----------------------
try {
out.close();
sock.close();
sock = null;
} catch (IOException e1) {
sock = null;
out = null;
}
}
} else
// if socket is null try to connect again (or firs time)
{
try {
sock = new Socket();
sock.connect(new InetSocketAddress(address,
5000), 1000);
out = new BufferedWriter(
new OutputStreamWriter(sock
.getOutputStream()));
} catch (IOException e1) {
sock = null;
}
}
}
}
});
thrd3.start();
Best regards,
Artik
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 07:06 -0800
Re: Java (android) socket reconnection Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-09 16:55 +0100
Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 08:26 -0800
Re: Java (android) socket reconnection Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-09 19:07 +0100
Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 12:36 -0800
Re: Java (android) socket reconnection Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-09 23:07 +0100
Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 14:45 -0800
Re: Java (android) socket reconnection Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-12-10 00:47 +0100
Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-10 13:09 -0800
Re: Java (android) socket reconnection Lew <lewbloch@gmail.com> - 2012-12-10 13:52 -0800
Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 08:34 -0800
Re: Java (android) socket reconnection Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-09 11:09 -0500
Re: Java (android) socket reconnection artik <olsztyn.arti@gmail.com> - 2012-12-09 08:33 -0800
csiph-web