• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

bugs in client\server program - can't connect to remote server

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

I have a client/server program in which client lets user input two numbers and the server adds the numbers and returns the sum to client.

the problems I am having are:

1. client is not able to connect to remote server. it is only connecting to local host.

2. if a string seperated by "non-numeric" characters (e.g. 34a2dd) is sent, both client and server throw an uncaught exception. i need to fix the client or server or both and give useful feedback to the user. i need to do the error checking of user i/p so that user enters only integers seperated by whitespace.

I am attaching my code.
I am new to java and probably don't know much.
'shall greatly appreciate your help.

thanks in advance,
sanjul



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

I have tried your program. Although I have not tried using it over a network, there's no reason it shouldn't. Make sure you are not using a firewall or router between the computers you are testing your program on. I put my own IP instead of "localhost" as default server, but that doesn't mean much.

Check out java.lang.Character, it has a method "isDigit()" and "getType()" which might be usefull for checking the users input.

Another note, if the client is restarted, your "sum" variable needs to be reset, otherwise you will add the new values to the previous sum.

good luck.
 
Sanjul Jain
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello! alex,

i tried connecting two computers on a same network w/o firewall. it is simply not working, and i have no clue why is it so.

i shall really appreciate if you kindly look into it.

regards,
sanjul
 
Alex Wolf
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,
ok i "looked into it", but i can't see a problem. I have tried it using a PC with windows XP running the server, and my macintosh OSX running the client. it works flawlessly. I put the IP address of the Windows XP computer here -> String hostName = "192.168.0.1"; and it worked just fine. I dont know how to fix your problem. It must have something to do with your computer. As far as fixing anything on windows, i'd say delete everything and reinstall - correct me if im wrong . do you have any other computers you could try it on?
 
Sanjul Jain
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!,

Thanks for your mail.

can you please show me how to do the second part - if a string seperated by "non-numeric" characters (e.g. 34a2dd) is sent, both client and server throw an uncaught exception. i need to fix the client or server or both and give useful feedback to the user. i need to do the error checking of user i/p so that user enters only integers seperated by whitespace

i tried using isDigit(), but 'am struggling with it.

i probably don't know much about java.

i will be really grateful for your help.

warm regards,
siddharth
 
Alex Wolf
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello again Sanjul,
im guessing your problem with the the Character class is because char and Character are not the same thing. here is some sample code to help you check for integers.

then you should put a try catch thing around the whole thing, and make a catch statement similar to this


if you want the server and the client to throw the exception then I would check the user input, and set a boolean if there were errors, send the text to the server and after that, if there were errors throw the exception, because if you throw the exception before you send the data, the server wont throw an exception...

Till next time.

or check the input after you have sent it.
[ December 06, 2004: Message edited by: Alex Wolf ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic