• 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

Multi Threaded client-server pair

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

I am trying to code a mutli-threaded client-server pair from a DefaultSocket class I created to contains common methods to both. I am not able to get this working and am receiving some exceptions. Can someone please help?

//common class


//server



//server


The exception I am getting at server side is:



I have already spent a lot of time debugging this but I am clearly missing something here. Please help
Thanks,
 
Marshal
Posts: 8856
637
Mac OS X VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

prachi vora wrote:I am not able to get this working and am receiving some exceptions.


Hi prachi, please be more specific at it.

"The more information you provide, the easier it is for people to answer your questions. Consider these examples:
[not helpful] My program throws an error.
[better] My program throws a NullPointerException on line 13. Below is the code and the stack trace.
The better one provides the reader with everything he/she needs to know to answer your question."


TellTheDetails (<--link, please find this page for more details)

[edit] It seems you added them after edited your post
 
prachi vora
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the line where I am getting exception.



I already posted the error message above. Not able to edit the post hence posting this one here.

Thanks,

edit: Yep, I forgot it first..So thought of updating..Maybe was in the process of editing when you replied
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something in that line is null when it shouldn't be. Probably oos.

Don't initialise your Streams in methods. Initialise them in the constructor. That way you will not have the references pointing to null. Or make sure the open connection method is called first.

Despite what you see in books like BruceEckel's, that Exception handling is horrible. Don't try to convert checked Exceptions to unchecked so as to get out of handling them. Handle those IOExceptions, even if it means closing the application with System.exit.
 
prachi vora
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for getting back...I tried the solution you mentioned. I called the OpenConnection() in the constructor of the DefaultSocketClient class. Still it doesn't work. Infact, this is giving the following exception:



This is the methid where exception is getting generated:


Thanks,
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Who on earth wrote that method? If you wanted examples of how not to handle exceptions you could hardly do better. Does it say anywhere what error code 13 means?
 
prachi vora
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote it like that because of requirements specified..It is coming from this part of the code..



Thanks,
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

prachi vora wrote:I wrote it like that because of requirements specified.



I don't have anything nice to say about those requirements, so I can't say anything about them on this forum. I'd just recommend that you write your catch blocks properly for now so that you can get rid of the bugs, and then rewrite then to follow those requirements once you have the code working reasonably well. Here's what I would recommend for a catch block:

 
prachi vora
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the exception I get after making the changes suggested by Ritchie..


The exception is coming from this line -->



Thanks,
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right. So your "sok" variable must be null, since that's the only variable where you're trying to access a member in that line of code.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start by finding whether that input stream is null. Or whether sok is null.
 
prachi vora
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried this line-->>



This is coming null for client..
 
prachi vora
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can someone please help?

Thanks,
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. You've found out that the "sok" variable is null, and it shouldn't be null. So why is it null? Find the code which assigns it a value: has that code been run? Was it run at the right time? What value did it assign? Come on, it's your code, you could put a little more effort into fixing the problem.
 
prachi vora
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for you suggestions. It's working now.

Thanks,
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good work!
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic