June 28th, 2003, 10:43 AM
any code for TCP socket programming
tell me the compiler too for that code.
June 28th, 2003, 11:34 AM
For what OS? Both Windows and Linux can use BSD sockets, but Windows requires Winsock support for which a few lines of code need to be added.
I compile my Winsock programs with either Visual C++ 6 or with the MinGW port of gcc (obtained through Dev-C++). In both cases, I need to include the wsock32 library. Of course, on Linux I just use gcc.
If you are just looking to get started, I started a sockets programming page, then went back to reorganize it and haven't gotten very far yet. It's at http://members.aol.com/DSC30574/sockets/index.html . Take the resources link on that page to my resources page at http://members.aol.com/DSC30574/sockets/resources.html . On that page, you will find compilers listed, as well as some books and web sites.
Check out the book, "The Pocket Guide to TCP/IP Sockets: C Version" by Michael J. Donahoo and Kenneth L. Calvert (2nd edition title: "TCP/IP Sockets in C: Practical Guide for Programmers"). If you're just getting started, this inexpensive ($15US) and thin (130 pages) book can get you up and coding fast. Their web site contains source code for the examples in the book (all for UNIX) plus the same source code translated over to Windows (except for the forked servers, since Windows does not support fork). Plus they provide links to instructions for writing Windows sockets programs (a couple of which I repeat on my resources page).
If you have some more specific questions, feel free to ask.
June 28th, 2003, 02:08 PM
i m new to C++ i have done all these things in java but i m doing this first time in C. for my requirements, i have to develop a server side for windows machine and the client sides for linux 7.2 machines so now guide me what compilers i have to use for windows and what for linux.
some one told me to use kdevelop for linux.and for winodows i m using borland Compiler.
waiting for ur answer
June 28th, 2003, 03:20 PM
For an example of a server using Winsock, look at the .zip file I uploaded for the "Windows XP and Sockets Part Deux" thread on this forum; reach it through this link, http://forums.devshed.com/t66453/sfd...4493942f2.html . rtimed is a tcp time server (port 37) to respond to my Linux laptop's rdate utility.
You should be able to compile it using your Borland C++ Builder, AKA "BCB" (I assume that is what you meant by "Borland compiler" -- we're talking about the need for Win32 support here). It was written as a console app using the MinGW port of gcc, but here's what it should take for you to compile it:
1. In BCB, create a new application. If it's able to make console apps, then go with that. If not, then you could have a button click create a worker thread for rtimed to run in -- my concern is that the server's infinite loop servicing requests does not cause the rest of your program to hang.
2. Copy the rtimed code into your application.
3. If you do not have support for getopt (you probably don't), then follow the instructions I give later in that thread for disabling that feature.
4. In the project options, add the library, wsock32.lib, or whatever it's called in BCB.
That should do it.
As for the clients, the suggestion you got about kdevelop sounds like you want them to be GUI apps. I've only done command-line apps so far, but the sockets code will be the same either way. My understanding is that you'll be using gcc anyway and in this case you shouldn't need to link in any additional libraries. However, sockets programming in Linux requires various header files.
So far, I've only written a few servers for Linux and my client apps have all been for Windows, so I don't have any examples of my own to show you. My suggestion is that you follow my previous suggestion of going to the website for the book, "The Pocket Guide to TCP/IP Sockets: C Version", and getting their example code there. Again, you will find the link through my sockets programming resources page at http://members.aol.com/DSC30574/sockets/resources.html .