• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't run client/server TCP chat due to java.net.ConnectException

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I'm trying to write a simple client/server TCP chat with Threads but I'm having problems when trying to run some of the codes.
As I'm using Socket, DataOutputStream and BufferedReader, Java makes me write "throws Exception" after each method that uses those objects. On the 'try' field, the object that uses BufferedReader (socketIn, from recieveMsg()) notices there's no one on the other side, listening to the port, and then it throws and exception (java.net.ConnectException).
I tried to use "finally' to execute it without throwing exceptions but I can't use it in the code - I don't know why and I don't know how (Java simply doesn't let me call the method inside 'finally' field). Also, i don't know if I'm using Threads correctly (I wish this part is OK), so I'd like someone's help, if possible, to solve this problem.]

Below, the codes I'm trying to run.

Client side


Server side


Thanks for everything.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic