Socket won't close after program is terminated

My socket won't close after my program is terminated regardless of if I use the .close method or not.
16 Replies
JavaBot
JavaBot3y ago
Hey, @Kar.Jar! Please remember to /close this post once your question has been answered!
fertiz
fertiz3y ago
can you send code?
Carter
CarterOP3y ago
Pastebin
Server Class - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Carter
CarterOP3y ago
Pastebin
Client Class - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Carter
CarterOP3y ago
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.
fertiz
fertiz3y ago
so the error is on client's side?
Carter
CarterOP3y ago
so basically the socket won't close the server object I created in the main method it has a ServerSocket object field
fertiz
fertiz3y ago
any errors?
Carter
CarterOP3y ago
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
fertiz
fertiz3y ago
its not about sockets. its about streama streams" you dont close them
Carter
CarterOP3y ago
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
fertiz
fertiz3y ago
you dont close DataInputStream
Carter
CarterOP3y ago
where can you show specifically? everything besides the ServerSocket that is reading and writing is implicitly closed with try-with-resources
fertiz
fertiz3y ago
you know what? my only tip is to puf serverSocket.close(); in try catches (error side) otherwise sorry, but I have no idea
Carter
CarterOP3y ago
all good this has been a real pain but there is probably a simple fix
fertiz
fertiz3y ago
sockets are pain

Did you find this page helpful?