How do I compare a string with client.read() ? - Page 1
Forum section: electronics / beginners

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 06:26:33 pm
content: Working on testing out a server ... I am having trouble comparing a string "test" with the client.read();char command = client.read();if (command == 'test') {server.write("it worked!");}it seems to work if I only compare with a single char, but not a string .. Is this only storing 1 byte or one char in the string or does the client.read() need to be converted into a string?

author: IanB
author_rank: Super Contributor
timestamp: September 05, 2013, 06:30:27 pm
content: I think you need to go find "ProgrammingHelpForNewbies.com"...This is not a homework help forum for elementary programming questions

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 06:32:15 pm
content: simple question. simple answer.

author: IanB
author_rank: Super Contributor
timestamp: September 05, 2013, 06:35:57 pm
content: But you make the classic mistake of assuming the reader knows all the context in your head without having to write any of it down.How is anyone supposed to know what "client" or "server" you are working with, on what system, nor where "client.read()" is defined or what its function prototype is?And if you are coding in C++, why don't you read a C++ book?

author: TopLoser
author_rank: Unknown
timestamp: September 05, 2013, 06:39:31 pm
content: 2 seconds with google and:http://arduino.cc/en/Reference/ClientReadclient.read returns a single character. Not a string.

author: c4757p
author_rank: Super Contributor
timestamp: September 05, 2013, 06:42:59 pm
content: Quote from: shermanator on September 05, 2013, 06:32:15 pmQuote from: shermanator on September 05, 2013, 06:32:15 pmFTFY

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 06:46:47 pm
content: If you don't know why i'm asking or what i'm asking in reference to , then it would be an intelligent response to ask what it is in reference to (if you cannot already see the obvious) rather than assume i'm a "newbie" who's doing a homework assignmentthis actually isn't c++ , if you cannot already tellit's not BASICit's not PERLit's not JAVASCRIPTit's not PHPit's not FORTRANI'm writing a small program on an Arduino board to test something very basic. I've noticed a lot of questions here regarding Arduino code , hence why i started the thread.

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 06:47:48 pm
content: Quote from: c4757p on September 05, 2013, 06:42:59 pmalready aware of that link , my question is not in reference to this"client.read returns a single character. Not a string."as stated in my post , that's obvious. my question is returning a string and comparing to another string , rather than comparing a single character to a string

author: DavidDLC
author_rank: Frequent Contributor
timestamp: September 05, 2013, 06:51:17 pm
content: So sad to see that people is lately attacking too much to the forum members.If you do not have something positive to say, just do not do it.Even if it is homework, if you see that the OP at least is trying something ( not asking how to do it from scratch, or asking somebody else to do it for the OP ), just help. I do not see Shermanator trying to get some advantage from somebody else.David.

author: 8086
author_rank: Super Contributor
timestamp: September 05, 2013, 06:51:53 pm
content: Quote from: shermanator on September 05, 2013, 06:46:47 pmIt would be more intelligent to post the context yourself.And, indeed, to not piss off those you expect to help you.

author: TopLoser
author_rank: Unknown
timestamp: September 05, 2013, 06:56:10 pm
content: You're going to have to read one character at a time and build a string out of them. Probably look for a CR character to indicate the end of a line from the client. Compare that string with what you're looking for.

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 06:56:39 pm
content: "piss off those you expect to help you"I didn't know you all were so sensitive.I'll make sure to go ask on a less sensitive forum.I wasn't aware this was a sensitive crowed that acts like they know shit and assume they know who you are then state they don't know what you're talking about and then respond with cocky dribble because they're somehow "offended" instead of acting like real programmers and communicating a basic answer or at least a somewhat-intelligent response.I'll go visit a different forum with real programmers. Adios. Pussies.

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 06:57:50 pm
content: Quote from: TopLoser on September 05, 2013, 06:56:10 pmyes, that's obvious.I am looking for a simple way around that , similar to how you would perform this in C++, perl, php or any other language.

author: 8086
author_rank: Super Contributor
timestamp: September 05, 2013, 07:00:40 pm
content: I thought you were off.Bye. Miss you already.

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 07:06:56 pm
content: i'll delete the thread so you can all quit your crying

author: IanB
author_rank: Super Contributor
timestamp: September 05, 2013, 07:18:54 pm
content: Quote from: DavidDLC on September 05, 2013, 06:51:17 pmWe are not attacking forum members, we are criticizing a behavior.The post at the top of the thread was post #1.This was someone new swooping in out of the blue, with no background and no context, and the first thing they say is "Hey, give me an answer to my simple problem!"That is simply not polite. You would not burst through the door of a tech meet in real life and, without even saying hello, start out with a basic question like "Hey! How do I wire a battery to a bulb to make the bulb light up?"Nobody is owed an answer to their rudely asked questions from a group of strangers. This is not a Q&A forum like Stack Overflow.

author: Unknown
author_rank: Unknown
timestamp: September 05, 2013, 07:28:18 pm
content: Maybe it would be useful to have a sticky similar toHow to ask questions the smart wayto refer people to?

author: Crazy Ape
author_rank: Regular Contributor
timestamp: September 05, 2013, 07:41:27 pm
content: Quote from: alm on September 05, 2013, 07:28:18 pmIt could be called "How to piss off those you expect to help you" with a reference to this thread.

author: madires
author_rank: Super Contributor
timestamp: September 05, 2013, 07:52:32 pm
content: Quote from: shermanator on September 05, 2013, 06:46:47 pmUsing client.read() and server.write("it worked!") tells something different.

author: baljemmett
author_rank: Unknown
timestamp: September 05, 2013, 09:47:27 pm
content: Quote from: shermanator on September 05, 2013, 06:56:39 pm'Real' programmers don't post completely context-free questions and expect those from whom they're seeking help to guess at everything else (such as what language you're using, what libraries you're coding against, what progress you've made on your problem so far and whether you have the slightest clue what you're doing). They also don't act like spoilt brats with the "yeah, I know that, but I want you to tell me what tools I have in my toolbox despite not telling you what that might be" attitude when someone does in fact attempt to help.Unfortunately you don't appear to realise that, which might explain why the response you got was more akin to "FOAD, HTH, HAND"; somehow I suspect you won't actually learn anything from the experience, though.

author: Bored@Work
author_rank: Super Contributor
timestamp: September 05, 2013, 09:59:32 pm
content: The sperminator is now pestering "real programmers" *cough* on an arduino forum, where he is properly spoon feed.

author: baljemmett
author_rank: Unknown
timestamp: September 05, 2013, 10:10:25 pm
content: Quote from: Bored@Work on September 05, 2013, 09:59:32 pmLook how shocked I am. No, really.

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 10:47:25 pm
content: Figured it out myself as usualI appreciate the open-source community and for those who contribute , I don't want somebody with the same question to stumble upon this thread only to hit a dead end so i'm posting the successful code below:Simple chat server with command feature , reads client.read() and stores data into string 'inData' then echos string to server (to confirm we have it). If client types "help" in the server, it back specific text to the client.#include <SPI.h>#include <Ethernet.h>// Enter a MAC address and IP address for your controller below.// The IP address will be dependent on your local network.// gateway and subnet are optional:byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };IPAddress ip(192,168,1, 4);IPAddress gateway(192,168,1, 1);IPAddress subnet(255, 255, 255, 0);// telnet defaults to port 23EthernetServer server(23);boolean alreadyConnected = false; // whether or not the client was connected previouslyString inData;void setup() {// initialize the ethernet deviceEthernet.begin(mac, ip, gateway, subnet);// start listening for clientsserver.begin();// Open serial communications and wait for port to open:Serial.begin(9600);while (!Serial) {; // wait for serial port to connect. Needed for Leonardo only}Serial.print("Chat server address:");Serial.println(Ethernet.localIP());}void loop() {// wait for a new client:EthernetClient client = server.available();// when the client sends the first byte, say hello:if (client) {if (!alreadyConnected) {// clead out the input buffer:client.flush();Serial.println("We have a new client");client.println("Hello, client!");alreadyConnected = true;}if (client.available() > 0) {// read the bytes incoming from the client:char thisChar = client.read();inData += thisChar;// echo the bytes back to the client:server.write(thisChar);// echo the bytes to the server as well:Serial.write(thisChar);// echo to the server what's been received to confirm we have the stringif (thisChar == '\n'){Serial.print("\nreceived:");Serial.print(inData);inData = "";}// if the string is "help" then return message to clientif (inData == "help") {server.write("\nYou said help!\n");}}}}

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 10:54:43 pm
content: Quote from: IanB on September 05, 2013, 07:18:54 pmSo you're criticizing behavior based on a questionyoudon't understand. You call somebody a newbie whom you don't even know. You claim they are doing a homework assignment when you have no idea what they're even working on.Real mature "behavior"Or am I mistaken , you are the self-proclaimed Mr. Know-it-all? If so I sincerely apologize, your heinous

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 10:57:36 pm
content: Quote from: baljemmett on September 05, 2013, 09:47:27 pmScroll up and read the thread captan obvious. My response has nothing to do with what's in my toolbox or not receiving an answer. It has to do with the over-sensitive muppets who like to dribble accusatory remarks because they're too full of themselves to respond in the simple words, like a real programmer would, i.e: "what are you referring to?". It's much more efficient to get to the bottom of something even if you have to admit you don't know what someone is talking about.. It's really that easy. No need to go on a tangent and throw a shit-fit because you assume somebody (you don't even know) is a newbie (because they ask a question you don't understand. That's all.

author: BillyD
author_rank: Regular Contributor
timestamp: September 05, 2013, 11:09:09 pm
content: Quote from: shermanator on September 05, 2013, 10:54:43 pmI think it's fair to say you brought that on yourself by barging in and asking a very basic question while failing to provide any context to it, and then made it worse by getting all snotty when people called you on it. With that attitude you'll very quickly run out of people willing to help you - and not just on internet forums but in life in general.

author: c4757p
author_rank: Super Contributor
timestamp: September 05, 2013, 11:10:40 pm
content: If you're asking how to compare strings, you are a newbie. It's that simple. If you had any coding experience you'd know exactly what you wanted and how to get it, because string comparisons are ridiculously common. And "homework assignment" was not an entirely unsafe assumption, since you were asking a very elementary question that most people just Google.And do you know why people were rude to you? This:Quote from: shermanator on September 05, 2013, 06:32:15 pmThis was the first instance of rudeness in the thread. You were told that you were asking in the wrong place and you demanded an answer anyway. Do you go on car forums and ask how to make ice cream? If you do, prepare to be told where you should go.

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 11:14:16 pm
content: Quote from: baljemmett on September 05, 2013, 10:10:25 pmNope the Sperminator is having fun watching a bunch of crybabies throw a fit because they claim they don't like the "behavior" of a so-called 'newbie' on a so-called 'homework assignment' asking a question , which they don't understand.It's really simple, "please elaborate". that's all you have to say. Unless you prefer acting like overly sensitive muppet.

author: AlfBaz
author_rank: Super Contributor
timestamp: September 05, 2013, 11:16:05 pm
content: Quote from: c4757p on September 05, 2013, 11:10:40 pmHowdoyou make ice cream, and in your response, make sure its chocolate, none of this vanilla crap

author: IanB
author_rank: Super Contributor
timestamp: September 05, 2013, 11:19:09 pm
content: Quote from: shermanator on September 05, 2013, 11:14:16 pmWe don't have to say anything. What makes you think we are obliged to help you?

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 11:25:01 pm
content: Quote from: c4757p on September 05, 2013, 11:10:40 pmMy question WAS NOT about comparing 2 strings. Again, read the question and look at the code.The entire response and attitude in this thread was very elementary. And a "homework assignment" was not an entirely unsafe assumption? considering you have no idea what i'm even referring to? Ok.The notion of real programmers has nothing to do with knowing how to compare strings or the difference of array's , etc. The notion of real programmers that I expressed more has to do with the humble attitude to seek more of that which what you do not understand , instead of throwing a fit and attacking somebody you don't even know because you somehow magically know they are a "newbie".QuoteScroll up captan obvious, the first instance of rudeness was the reply to that post (the second post). My post in response to that second reply (first instance of rudeness) was "SIMPLE QUESTION, SIMPLE ANSWER" . Maybe it's not considered rude when somebody rather make immature remarks and attacks instead of simply asking what somebody is talking about if they don't understand or ask them to elaborate.

author: Unknown
author_rank: Unknown
timestamp: September 05, 2013, 11:27:52 pm
content: No point in continuing arguing about this. Coming back and posting a solution is a positive contribution, and I don't think the OP is looking for additional help.

author: c4757p
author_rank: Super Contributor
timestamp: September 05, 2013, 11:28:29 pm
content: Quote from: AlfBaz on September 05, 2013, 11:16:05 pmWalk to the corner store, place a container of delicious, chocolate* ice cream on the counter, and exchange money for it. That's how I do it - works every time*I realize "delicious, chocolate ice cream" is an oxymoron, but I will humor you, since chocolate is apparently a tasty flavor of ice cream in your screwed-up, delusional world.

author: baljemmett
author_rank: Unknown
timestamp: September 05, 2013, 11:29:44 pm
content: Quote from: shermanator on September 05, 2013, 10:57:36 pmStrange as it may seem, I did read the thread; if I may quote:Quote from: shermanator on September 05, 2013, 06:57:50 pmWhich is exactly the attitude I was commenting on. Speaking as an actual real programmer, by the time I saw this thread I couldn't see a single reason I'd want to invest any effort in helping you - even if IanB's initial response to your question wasn't particularly helpful, you persisted in providing fuck all by way of relevant information and then acted like a complete dipshit when called on it.Dismissing the advice you did receive as 'obvious' when we have no way of knowing what you already know is just outright childish. Why do you think it's our job to figure out what you already know, when you could (and should) provide this information upfront so we know how to pitch the response?

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 11:32:12 pm
content: Quote from: alm on September 05, 2013, 11:27:52 pmI posted the solution already after figuring it out.. You probably have to go back a few responses to see it.I hope somebody with the same question who stumbles onto this thread can find this post beneficial , unfortunately they'll have to sift through all the crybabies who seemed to swarm here like a bunch of fruit flies to add their 2-cents of ridiculous arrogant sensitivity.

author: c4757p
author_rank: Super Contributor
timestamp: September 05, 2013, 11:35:37 pm
content: Quote from: IanB on September 05, 2013, 06:30:27 pmThisis what you call rude, Captain Vague? This?? Have youmetanother human before? Seems more of a joke to me, personally. And yes, that is a very typical response when a brand-new member of a forum asks a completely offtopic question. Go try it elsewhere and report back.Quote from: shermanator on September 05, 2013, 11:32:12 pmAre you Pot, or Kettle?

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 11:37:17 pm
content: Quote from: baljemmett on September 05, 2013, 11:29:44 pmDismissing advice? I really think you're either 1) far too sensitive or 2) looking for a way to justify your argument on who came off rude in this forum which started this whole tangent parade.Why would you even argue that someone thinks it's your job to figure out what somebody already knows or should know? How do you even reach that conclusion? I asked a simple question, which was immediately met with a bullshit remark. Which was followed by more bullshit from people who felt like they were somehow disrespected somehow.I did provide additional information to what I was referring to even though instead of asking folks wanted to act like sensitive little muppets on a crybaby fit and launch little attacks.Nonetheless , I still came back after figuring it out myself and posted the result hoping that somebody with the same question doesn't have to deal with sensitive ass brats who think everyone in the world besides them is a "newbie"

author: c4757p
author_rank: Super Contributor
timestamp: September 05, 2013, 11:40:45 pm
content: "Newbie" isn't an insult, dude...

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 11:45:04 pm
content: Quote from: c4757p on September 05, 2013, 11:35:37 pmOk, if that's not rude by your standards then we all have nothing more to complain about. You shouldn't have a problem with my "rude" question or my "rude" response , which was in response to the second post.And met another human? You forgot you're on an INTERNET FORUM. As far as I know you're 600lbs and sit there all day with a shit and piss bucket eating hot pockets and pancakes that drip syrup on your belly. No? Well according to the logic here, that's a perfectly safe assumption.I don't need to go try elsewhere , i figured out the issue and posted the successful result in hopes of at least making this thread worth while for somebody. You'll have to scroll back through all the crying and ranting to see it.

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 11:46:18 pm
content: Quote from: c4757p on September 05, 2013, 11:40:45 pmOf course not , newbie.It's in the context you use it in, newbieAs with any adjective, newbie.example:TEXT DELETEDcontext.

author: c4757p
author_rank: Super Contributor
timestamp: September 05, 2013, 11:49:09 pm
content: Quote from: shermanator on September 05, 2013, 11:45:04 pmHave... have you been stalking me?They'rewaffles. I think you need eyeglasses.

author: shermanator
author_rank: Contributor
timestamp: September 05, 2013, 11:50:28 pm
content: Quote from: c4757p on September 05, 2013, 11:49:09 pmwaffles sound good right now

author: Monkeh
author_rank: Super Contributor
timestamp: September 05, 2013, 11:53:39 pm
content: I could definitely go for waffles.Wait, how'd I end up in here? Oh well. Handbags down, girls, before somebody breaks a nail.

author: AlfBaz
author_rank: Super Contributor
timestamp: September 05, 2013, 11:56:30 pm
content: Quote from: Monkeh on September 05, 2013, 11:53:39 pmaahh, yet another precious "coffee sprayed over the monitor moment"

author: ve7xen
author_rank: Super Contributor
timestamp: September 06, 2013, 12:30:07 am
content: Quote from: shermanator on September 05, 2013, 11:46:18 pmAnd here it seemed like the concept of context wascompletelylost on you.Ask good questions, get good answers.

author: c4757p
author_rank: Super Contributor
timestamp: September 06, 2013, 12:52:12 am
content: Quote from: shermanator on September 05, 2013, 11:46:18 pmMy incorrigible potty mouth will usually support any instance of swearing at all, but anybody who says "yo that $x is dope motherfucker" needs to be ostracized from the community of language-users.

author: Bored@Work
author_rank: Super Contributor
timestamp: September 06, 2013, 05:36:02 am
content: Quote from: shermanator on September 05, 2013, 10:47:25 pmNo, you didn't. That junk you are posting here is what they spoon fed you in that Arduino forum. You have no clue how it works. You have no clue how to change it, how to adapt it and how to fix it. You are just doing copy-paste. That is not "figuring things out myself", that is just imitation.What you do is a sad demonstration of unwillingness to learn, unwillingness to understand things and unwillingness to evolve beyond a copy-paste arduino joke.

author: mrflibble
author_rank: Super Contributor
timestamp: September 06, 2013, 06:45:49 am
content: http://stackoverflow.com/questions/7606816/arduino-ethernet-and-dhcp-cannot-communicate-out-to-the-internetOne of many code snippets out there. Looks like hetotally figured it out by himselfAND invented a time machine. So now he can travel back and sign up for that Effective Communication course he knows he should have taken years ago.

author: IanB
author_rank: Super Contributor
timestamp: September 06, 2013, 07:01:54 am
content: I had to smile at the moderator comment at the end of that other thread:QuoteIt's a hard life being a moderator...

author: mrflibble
author_rank: Super Contributor
timestamp: September 06, 2013, 07:30:19 am
content: Heheh, I noticed the very same thing. XD See that a lot on another forum as well. Verilog plain-text-without-indentation-or-highlights ... or properly formatted and readable code, decisions decisions.

author: Rigby
author_rank: Super Contributor
timestamp: September 06, 2013, 09:20:35 am
content: Here's the thing: one can criticize another, while simultaneously expressing a positive and encouraging tone easily enough. Instead people choose to express a tone that communicates little more than "I already dislike you, you're an idiot, do the work yourself, you're not welcome here."I myself have avoided asking many, many questions because I have a feeling that many of you will respond negatively. So, I don't ask. I research when I can, and I know there are people here that can help guide me but I dare not speak up.The worst thing about any hobby is always the community. I used to say that the best thing about any hobby is the community, because that used to be true.

author: TopLoser
author_rank: Unknown
timestamp: September 06, 2013, 09:45:08 am
content: There were several fundamental issues with his initial post.1. The subject title was utter nonsense. The question just didn't make sense. He should have put a lot more thought into letting people know what his actual problem was. We can try and read peoples minds but in his case it didn't seem worth the effort to be honest!2. The body of his post wasn't exactly illuminating either. There was just a chunk of random code with no helpful additional information, and an obvious lack of understanding of very simple concepts. Just a cocky 'make this work for me' attitude.A bit of thought put into that initial post would have prompted far more helpful responses.He didn't seem short of words later into the thread though, I'm sure he was putting more thought, time and effort into his rantings instead of trying to solve his problem.

author: digsys
author_rank: Unknown
timestamp: September 06, 2013, 10:47:07 am
content: Quote from: RigbyDon't let a few derailed threads put you off, or stop you asking questions. Once you understand the "life force" of a web forum,it's not difficult to avoid the cr@p. Mostly it's about probability. Many posts, perceived dumb or otherwise, get answered withgreat content and attitude. There are many cases, all the time. It all depends on WHO just happened to see you post first, and ifthey were in their PMS cycle at the time. And once negative replies start, social "mob" forces usually attract more of the same.PLUS there are few "regular / high count" posters (who should know better) that have taken position of ownership and won'tback down. They rarely even bother to try to understand an OPs question, or if this is their native language.IF it happens to you, and I've had respondents here do it to my posts, don't bother replying to the stupids.Either, wait it out, or try again in a new time zone with a new thread. Often, it's not worth trying to save a derailed thread.Don't let the clowns stop you ! The Internet is a rich breeding ground for them.

author: Rigby
author_rank: Super Contributor
timestamp: September 06, 2013, 12:08:23 pm
content: Quote from: TopLoser on September 06, 2013, 09:45:08 amI'm not arguing any of that. In fact, I agree with you.I'm arguing that the initial post quality, no matter what it is, should solicit help or advice, rather than condemnation. If there isn't enough information to answer the question, or even if there isn't a question, guidance on what is required would go a lot further than immediate rejection or dismissal.I came here expecting (naively, as always) altruistic motivations from those who bother to respond to a question. I do see that, and I also see a great deal of criticism and contempt. At that point, those folks are now a clique of divas. It is that which I dislike.Truthfully, I should expect this by now. I've been participating in conversations online for over 20 years. I'm not sure if my constant surprise at the discovery of hobby cliques is due to my own stupidity or my own optimism. I guess it doesn't matter.I'll just end this with an edit. My grandfather always said "there is no person on this planet that you cannot learn from." My brothers interpreted this as "you are so stupid that everyone knows more than you." I took it to mean that "no one holds a complete superset of another's knowledge." It is likely that this lesson (my interpretation of it) drives my own altruistic or helpful actions. I've learned a great deal by answering questions and talking to people that need help, even when I thought they had a lot to learn.

author: AlfBaz
author_rank: Super Contributor
timestamp: September 06, 2013, 12:49:35 pm
content: Quote from: Rigby on September 06, 2013, 12:08:23 pmHave you ever been a member of a forum where you were the one helping and answering others?I am not one here but have been on other micro forums and it can sometimes take a lot of effort to help somebody through a problem. Copying and pasting code, compiling it, simulating it, reading manuals and data sheets, searching the net etc, etc.Then you come across a post where the person is asking a question that can easily be found with a quick search, in some forums the answer may be in the FAQ section. Still no big deal, if you know the answer and its a quick and easy reply away you go, but when the question is framed in such a way that it is evident the person has not only put no effort into finding an answer but is putting no effort into asking the question and then to top it off the question is not being asked, its being demanded you are bound to cop a serve. In fact I think the response from members here were quite moderate in comparison to the utter bone headedness of this OP.Yes it is a community and in a community a little effort goes a long way