Pages

Showing posts with label Socket Programming. Show all posts
Showing posts with label Socket Programming. Show all posts

Sunday, July 4, 2010

Tips for socket programming lab2

1. Important point you can only type cast a pointer into another, it implies that you can not type cast an integer to the type void * etc.
2. The last argument of the thread function takes a void pointer as its argument so firstly keep point 1 in mind and secondly either you can declare a pointer or the better option might be to simply pass the variable by reference.
3. If you passed a variable by reference don't forget to dereference it. syntax * referenced_variable
4. When you compile the code, keep in mind that now you need to tell the compiler that it needs to use the lpthread library at link time. So don't forget to make relevant changes to your make file.
5. Enjoy your programming, its never too late to learn :)

Friday, July 2, 2010

iostream buffer issues, cin, cout, cin.get, cin.getline

Here are useful links to iostream buffer related issues.

http://www.cplusplus.com/forum/beginner/7405/
http://www.cs.hmc.edu/~geoff/classes/hmc.cs070.200109/notes/io.html


you may also wish to read the chapter on I/O in the book by Walter Savitch, it is available in the library

In case you are having issues where your code seems to skip cin or cin.getline you can use
std::cin.ignore(std::numeric_limits::max(),'\n');
or, since you have 'using namespace std;', you can add this
cin.ignore(numeric_limits::max(),'\n');

to flush the buffer before you take input you will need to include ios.h and limits.h in order for it to work

sample

# include
# include
# include
# include
using namespace std;

int main()
{

.
.
.
.
.

string string1;
cin.ignore(numeric_limits::max(),'\n');
cin.getline(cin,string1);


}

Wednesday, June 30, 2010

Socket Programming

Here are a few helpful links for those who wish to learn socket programming.
http://www.tenouk.com/cnlinuxsockettutorials.html start from ch 1 and continue further, there is no end to iy, it all depends on how much you wish to learn. :)

For those of you who are getting jumpy and dont want to go through the details this page lists the details of the functions and there parameters that are being used. http://www.tenouk.com/Module39b.html

You can download and run the client and server executables to see what output is expected from you.