B
Berlin Brown
Maybe I have this completely wrong, but for a java based client-server
chat style application. Cant I just open a socket at init or load for
example and then re-open the outputstream or inputstream at any time and
send or receive accordingly. Well that doesnt work. I call
getOutputStream(), send my data and I lose my socket connection when I
enter this method again? Too much code to post, but here is the jist.
Applet() {
init(){
socket = new Socket()
}
actionPerformed() {
OutputStream o = socket.getOutputStream()
o.write.flush()
InputStream i = getBytes()
//sometimes I close outputstream, sometimes I dont
// same result
When I call the actionPerformed again, I get a SocketException the
socket is closed. The data goes and I can get data back.
To fix for the time being, I just put the socket connection open in my
actionperformed.
Maybe my thinking of java sockets is wrong, I know this standard fair in C.
}
chat style application. Cant I just open a socket at init or load for
example and then re-open the outputstream or inputstream at any time and
send or receive accordingly. Well that doesnt work. I call
getOutputStream(), send my data and I lose my socket connection when I
enter this method again? Too much code to post, but here is the jist.
Applet() {
init(){
socket = new Socket()
}
actionPerformed() {
OutputStream o = socket.getOutputStream()
o.write.flush()
InputStream i = getBytes()
//sometimes I close outputstream, sometimes I dont
// same result
When I call the actionPerformed again, I get a SocketException the
socket is closed. The data goes and I can get data back.
To fix for the time being, I just put the socket connection open in my
actionperformed.
Maybe my thinking of java sockets is wrong, I know this standard fair in C.
}