• 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:

Problem in UDP client/server application....

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have put in some sysouts in your code. Are you seeing those as expected?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic