File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Can't run client/server TCP chat due to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Can Watch "Can New topic

Can't run client/server TCP chat due to

Guilherme Cahu

Joined: Feb 28, 2013
Posts: 1
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 (
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.
subject: Can't run client/server TCP chat due to
It's not a secret anymore!