Solved

Accessing Winsock with Delphi 2.0

Posted on 1997-03-18
3
348 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now