Friday, July 31, 2009

Write program in C that transfers string "Hello" to connected computer, the receiver should respond with "Hai"

u need to search messaging in c++ and study

Write program in C that transfers string "Hello" to connected computer, the receiver should respond with "Hai"
I'm *guessing* at the question here. I'm supposing that there are two computers and you want one to send the other the word "Hello" and the other to send back the word "Hai".





There's a few ways of doing this, but underneath it all it boils down to sockets in some form or other.





I won't write out the code explicitly (a bit of digging around followed by some trial and error on your part and you should have it working quite quickly)





For the purposes of this example, suppose there's a 'remote' computer and you want it to run a TCP listening 'service' or whatever you want to call it.





open a socket (tcp=SOCK_STREAM)


bind to the socket


listen on the socket


accept on the socket


recv some bytes


check those bytes are "hello"


send "Hai"


close the socket





Here's your 'local' client:


open a socket


connect to the socket


send "Hello"


recv some bytes back


close the socket.
Reply:sound to me you are taking on a basic c program language. that is what they all teach you in tech class. your basic "hello" programs.
Reply:This also sounds like something you'll want to find out how to do yourself, so that when the instructor tests you on the concepts you won't be clueless and then fail the exam and eventually the class, and later get fired from a job for not knowing how to do something you said you could but really didn't because you didn't do your own homework and practice the concepts yourself.

magnolia

No comments:

Post a Comment