#Socket won't close after program is terminated

1 messages · Page 1 of 1 (latest)

light prawn
#

My socket won't close after my program is terminated regardless of if I use the .close method or not.

cinder kelpBOT
#

Hey, @light prawn!
Please remember to /close this post once your question has been answered!

worldly fossil
#

can you send code?

light prawn
#

the gist of the program is that it takes in console input in the Client class and sends the message to the server and outputs a different message with the date.

worldly fossil
#

so the error is on client's side?

light prawn
#

so basically the socket won't close

#

the server object I created in the main method

#

it has a ServerSocket object field

worldly fossil
#

any errors?

light prawn
#

a bind exception

#

the ServerSocket is creating a connection but it's not killing it once the program ends

#

so I can't use the same port if I end the program unexpectedly without a Bind Exception

worldly fossil
#

its not about sockets. its about streama

#

streams"

#

you dont close them

light prawn
#

wdym

#

I'm using try with resources, I wanted to avoid using that with the SocketServer because I want to keep it as an instance variable

worldly fossil
#

you dont close DataInputStream

light prawn
#

where

#

can you show specifically?

#

everything besides the ServerSocket that is reading and writing is implicitly closed with try-with-resources

worldly fossil
#

you know what? my only tip is to puf serverSocket.close(); in try catches (error side)

#

otherwise sorry, but I have no idea

light prawn