This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in UDP client/server application....

 
Prateek Rawal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

SERVER CODE:


CLIENT CODE:

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.....
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have put in some sysouts in your code. Are you seeing those as expected?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
pda123
threat-pc124
piyush_ulti125

and i send the following name from client:
pda

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 -1......how 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!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic