[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Accessing Winsock with Delphi 2.0

Posted on 1997-03-18
3
Medium Priority
?
390 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 200 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 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