hi there,

i am trying to make a client/server program for my project.
i have created a menu that gives 3 options which in turn would take you to its corresponding method in my client. the method would run and send over some info to the server as a string. what i want to do is put a character into the first part of the array ( i believe this to be arrayname [0] and not [1]) so that when the server reads in the first character it can recognise it and send it to the correct path.

i.e 
if arrayname[0] ==Q   do this bit
else if arrayname[0] ==C  do this
else if arryname[0] == s do this
else send error code

can anyone tell me how this could be done, and how it can be done using tab spacing ?

cheers

fatboy

Recommended Answers

All 5 Replies

Just make the menu option the first character of the string that the client sends to the server. But I think that is what you already said. I have no idea what the remainder of that string will be.

>>and how it can be done using tab spacing ?
Huh? No idea what that means.

Hi dragon,

"Just make the menu option the first character of the string that the client sends to the server"


Thats the bit i don't know how to do.

Also when reading at the other end, i will have 3 bits of information in the string and need to get each bit individually that why i thought of tab spacing to make reading each bit easier. The string will be of varying lengths so i cannot just read say 8 characters.

thanks

Its not bits but bytes. The smallest thing you can send from client to server is a byte, which is normally 8 bits. The letter 'Q' is one byte.

>>Also when reading at the other end, i will have 3 bits of information in the string

No, what you probably mean is that the server will get 3 bytes of information. Just treat it like you would any other character array.

Ok here goes,

the returning message will have for example the letter 'Q' as it's first byte.

That will tell me how to get to the correct part of the program.

i will then have two further pieces of information within the array, however i will not know how long each piece will be. In other words i do not know how many bytes of information there are. the question asks for me to give a list of TV programmes based of category and sub category i.e. news ( local/national), current affairs, entertainment (films, comedies, soaps), sports (footy, cricket basketbal) etc.

How can i solve this ? i thought if i maybe put in some blank bytes after each piece of information like a tab space perhaps ????

Is there an easier way of distinguihing where one ends and the other starts.

you could put the length of each string before it, which is similar to how I do it. Or terminate the string with a character you KNOW will never be in the string. Spaces are not good for this because the strings will probably have enbedded strings. The pipe symbol '|' or tab character are often used as terminators.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.