my dog learned polymorphism*
The moose likes Sockets and Internet Protocols and the fly likes bugs in  client\server program - can't connect to remote server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "bugs in  client\server program - can Watch "bugs in  client\server program - can New topic
Author

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

Sanjul Jain
Greenhorn

Joined: Oct 21, 2004
Posts: 14
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



Alex Wolf
Greenhorn

Joined: Aug 24, 2004
Posts: 16
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

Joined: Oct 21, 2004
Posts: 14
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

Joined: Aug 24, 2004
Posts: 16
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

Joined: Oct 21, 2004
Posts: 14
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

Joined: Aug 24, 2004
Posts: 16
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bugs in client\server program - can't connect to remote server
 
Similar Threads
port number
Simple problem in running a Server class
display http header
cleint-server interaction
Running a client/server apllication