delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Simple Winsock Component for console app.Format this article printer-friendly!Bookmark function is only available for registered users!
Console winsock component
Product:
Delphi all versions
Category:
Internet / Web
Skill Level:
Scoring:
Last Update:
09/15/2003
Search Keys:
delphi delphi3000 article borland vcl code-snippet winsock console internet connection small exe TCP/IP
Times Scored:
2
Visits:
4402
Uploader: J3N7iL Jones
Company:
Reference: N/A
 
Question/Problem/Abstract:
how can i creat a TCP/IP internet connection in a console application using winsock?
Answer:



This is a whole component that you can save to a *.pas file and use to create internet connections from within a console application. Its very basic and very simple. All it does is connect, read, and write. Enjoy!


UNIT GSB_Socket;

{$A+,B-,C-,D-,E-,F-,G+,H+,I-,J-,K-,L-,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBASE $00400000}

///////////////////////////////////////////////////////////////////////////////
// GSB_SOCK was coded by J3N7iL (EES) as a going away present to the newbies!
// Unfortunatly, I have been consumed by real life,
// and must depart from the scene. It's been a blast, you all have been great!
//
// This is at the most, the simpleset working WINSOCK component.
// All it does is connect to an ip, read, and write.
// Feel free to change, edit, add, or print it out and use is as toilet paper.
//
// This is what i now use for my SMTP connections,
// and of course my IRC & yahoo bots.
// But because its TCP/IP, it can be used for every widley used connection
// including ICQ notify, FTP Protocol, and PHP notify.
//
//*****************************PLEASE FOR THE LOVE OF GOD!**********************
//            If your going to post this on a site, or distribute it,
//                       LEAVE THIS HEADER INTACT!!!

INTERFACE

uses
  winsock, windows;

TYPE
rsp = function(dwProcessID,dwType:DWord):DWORD;stdcall;
Procedure StartWSA;
Function Open(Port : integer; Address : string) : integer;
Function Read(var buff; len : word): word;
Procedure write(Data : string);

VAR
  WSAData: TWSAData;
  GSB_SOCK: TSocket;
  sin   : TSockAddrIn;
  WsaReady : Boolean = False;

IMPLEMENTATION

Procedure StartWSA;
Begin
IF WSAStartup(257,WSAdata) = 0
  THEN
   WSAReady := true;
END;

Function Open(Port : integer; Address : string) : integer;
BEGIN
StartWSA;
  If WsaReady = TRUE
   THEN
    BEGIN
     GSB_SOCK := socket(PF_INET, SOCK_STREAM, getprotobyname('tcp').p_proto);
     sin.sin_family := PF_INET;
     sin.sin_port := HTONS(PORT);
     SIN.sin_addr.S_addr:= inet_addr(PChar(Address));
     Result := connect(GSB_SOCK,SIN,sizeof(SIN));
    END;
END;

Function Read(var buff; len : word): word;
begin
  IF WSAReady then
  result := recv(GSB_SOCK,Buff,len,0);

END;

Procedure write(Data : string);
Var
  Datasize : integer;
BEGIN
  datasize := length(data);
  IF WSAReady then
  send(GSB_SOCK,Data[1],datasize,0);
END;


initialization
  StartWSA;
finalization
  WSACleanup;
END.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
M. Maes
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)