Solved

Accessing Winsock with Delphi 2.0

Posted on 1997-03-18
3
359 Views
Last Modified: 2010-04-04
How do I use Winsock with Delphi 2.0 to initiate FTP protocols for uploading and downloading files to an FTP server using a dial-up connection.  I also need to know how I use Winsock to login into a POP server for an email program and HTTP programs.  I need the general info to get me started, so if you need more specific info, let me know.
0
Comment
Question by:peteyj
3 Comments
 
LVL 3

Accepted Solution

by:
mheacock earned 100 total points
ID: 1334894
Using Winsock at the API level is reasonably complex...there are synchronization details you have to beware of, buffering, etc.

I don't mean to be rude, but it sound as if you do not know that much about Winsock, or are at least new to it.  I'd suggest going to the Delphi Super Page and picking up a Winsock component (there are a lot there)...you'll find them easier to use as they will handle all the nitty-gritty details for you and you can concentrate on the higher level stuff you probably want to perform.

The URL of Delphi Super Page is:

   http://www.cdrom.com/pub/delphi_www/

Feel free to comment.  I don't mean to steer you towards the easier route, but if you are new to Winsock, like I suspect, you'll save yourself much aggrevation and headache buy checking out the freeware/shareware winsock components available.

I've done a bit of Winsock programming at the API level.  I don't anymore.  What's the point.  Enough people have already invented the wheel, why try and reinvent it.  I say, if someone else has done it well and they are offering it to you, then use it.  Don't fall into the trap of thinking you have to know everything at the lower-levels...you don't...and if you do try, you'll find yourself falling further and further behind the technology...thigns are moving to fast today to be able to understand everything.

Oops...sorry for the lecture.

The point is this...if you want code to perform what you are asking at the low-level, then you probably won't get it here.  Winsock is complex and the code you require would be fairly lengthy.  So, check out some shareware/freeware.

Redundantly yours,
0
 

Expert Comment

by:mlanza
ID: 1334895
Those who are interested in programming the WinSock API from Delphi would find the book "Delphi 2 Developers Solutions" very useful.  It takes you through creating FTP, SMTP & POP projects.  Full source code on CD.

Publisher:  Waite Group Press
ISBN:  1-57169-071-9
0
 

Expert Comment

by:peteraa
ID: 2918440
How do I use Winsock with Delphi 2.0 to initiate FTP protocols for uploading and downloading files to an FTP server using a dial-up connection.  I also need to know how I use Winsock to login into a POP server for an email program and HTTP programs.  I need the general info to get me started, so if you need more specific info, let me know.

For FTP and HTTP I use Wininet. It works well and its a lot easier...
Heres an an example

Program project1;

uses
Windows, Wininet, Sysutils;

{$R *.res}

var
ISession, Connection, HTTPReq: HINTERNET;
retstr:string;
Data: Array[0..$400] of Char;
BytesToRead: DWord;

begin
ISession:=InternetOpen(PChar('UserAgent'), LOCAL_INTERNET_ACCESS, nil, INTERNET_SERVICE_HTTP, 0);

Connection:=InternetConnect(Session, PChar('www.yourserver.com,'), 80, Pchar(''), Pchar(''), INTERNET_SERVICE_HTTP, 0, 0);

HTTPReq:=HttpOpenRequest(Connection, PChar('GET'), PChar('directory/filename.ext'), PChar('HTTP/1.1'), Pchar('Refferer'),PChar('text/html, image/gif, */*, etc'),    $8000000, 0);

HttpSendRequest(HTTPReq, '', 0, nil,0);

while True do
               begin
               if not InternetReadFile(HTTPReq, @Data, Dword(SizeOf(Data)),BytesToRead) then
               begin
               messageBox(0, 'An error occured while accessing the Server', Pchar('Peters emu'), MB_OK);
               break;
               end
               else
               if BytesToRead = 0 then break
               else
               retstr:= retstr+ Data;
               end;

               internetclosehandle(HTTPReq);
              internetclosehandle(ISession);
              internetclosehandle(Connection);
end.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question