Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ Newb: Win & Unix Socket Programming

Status
Not open for further replies.

Flappy

Programmer
Jul 30, 2002
35
AU
Hi guys,

I've been programming all my CGI scripts in Perl and now want to change over to C++ to speed them up a bit.

I've got a simple email submit program that I wrote in Perl and I'm not sure how to go about it in C++, I want to connect to the mail server using sockets but I want the program to be able to compile under Unix and Win32. I know I could pipe the contents of my email to sendmail but thats no good for Windows.

Here is what I want to do in C++:

$remote=IO::Socket::INET->new("localhost:smtp(25)");
$remote->autoflush();
print $remote "HELO\r\n";
$trash=<$remote>;
print $remote &quot;MAIL From: $from \r\n&quot;;
$trash=<$remote>;
print $remote &quot;RCPT To: $to \r\n&quot;;
$trash=<$remote>;
print $remote &quot;DATA\r\n&quot;;
$trash=<$remote>;
print $remote $content;
print $remote &quot;\r\n.\r\n&quot;;
$trash=<$remote>;
print $remote &quot;QUIT\r\n&quot;;
$trash=<$remote>;
close($remote);

Any help appreciated.
 
Hello, I have some examples of C/C++ code classes that you could use for CGI scripts (I recently changed my CGIs over from Perl). However, I have them on a different PC which I can't access till the morning. If you give me your email address I can send them to you. They include getting all the env variables into a linked list (array), mailing from within the program, URL redirection and a comprehensive string class.
If you want to learn more about socket programming for (or between) Windows and Unix, there's a great little PDF file available on the web called &quot;Beej's Guide to Network Programming&quot; (do a search for it) that'll get you off to a flying start. It also contains two client/server example programs (both STREAM and UDP) written in C/C++.
Hope this helps.
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Thats great! Sounds excatly what I want to do - I've already written the classes for parsing URL strings and constructing the email etc. its basically just the network programming and sockets that I've got no idea about..

My email address is v.sui@optushome.com.au.

I'll start searching for that PDF that you are talking about now

Thanks!
 
Hi Flappy, if it's just the networking side you're concerned about then the PDF doc should answer all your questions. If you need any other info re. converting CGI from Perl to C/C++ then just give us a shout - we're always happy to help. :)
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top