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 Problem in UDP client/server application.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Problem in UDP client/server application...." Watch "Problem in UDP client/server application...." New topic

Problem in UDP client/server application....

Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
Hey everyone,

i'm interested in creating a client/server application in which server stores the names and phone numbers of 10 persons and when client sends a name, the server looks up in the array. If the name send by the client is present in the array, it sends the corresponding phone no to the client.....

The code goes something like this:



However the problem that im facing is that the function indexOF() returns -1 even if the name typed by the client is present in the array.
for example:
if s1 = the string which takes data of array present at evry index = pda123
and s = name send by client = pda
then also
s1.indexOf(s) returns -1

However when i manually took two strings of same name pda123 and pda and applied the same function, then it returns 0 as expected.

I can't understand how is it even possible....
It is blowing up my mind. Please help urgently.....

Waiting for enlightenment....
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
You have put in some sysouts in your code. Are you seeing those as expected?

Thanks and Regards
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
In the future, please UseCodeTags. It's unnecessarily hard to read the code as it was, making it less likely that people will bother to do so.
Prateek Rawal
Ranch Hand

Joined: Dec 19, 2009
Posts: 90
Yeah, I will remember that in future......

As far as sysouts are concerned......i have put them to test whether the data recieved by the client is correct and the data at every index of array is retrieved corrrectly.....

For eg: i entered the following three names in array

and i send the following name from client:

then i print whether s1 = data at index of array, gets pda123 at 1st run of the loop or not,,,it does s1=pda123.....
then i print whether s = data send by client, gets pda or not,,,,it does s = pda

but when i did s1.indexOf(s) it returns is it possible?

however when i manually took two strings s2 = pda123 and s3=pda, then when i did s2.indexOf(s3) it returns 0 as expected.......

Why is this happening,,,,please help!!!
I agree. Here's the link:
subject: Problem in UDP client/server application....
It's not a secret anymore!