[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

Winsock problem

Hi everybody,

I want to know everything about Winsock, so I read al lot of  the
questions about WinSock in this forum and searched in google about Win-
sock.

I made this code because I want to connect to an existing AS400 server:

I know how to  declare and allocate a socket and make a connection
to a server, and Send a command, but when I send a command
I get nothing in return. Can somebody help me to get a reaction
from the server:

procedure TForm1.Button1Click(Sender: TObject);
var
  wVersionRequested: WORD;
  wsaData: TWSAData;
begin
  wVersionRequested := MAKEWORD(1, 1);
  WSAStartup(wVersionRequested, wsaData);
  if WSAStartup($101, WSAData) <> 0 then begin
    Memo1.Lines.Add('WSAStartup error')
    end else
    Memo1.Lines.Add('WSAStartup OK');
  end;
(*---------------------------------------------------*)
procedure TForm1.Button2Click(Sender: TObject);
begin
  fSocket := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if fSocket = INVALID_SOCKET then Memo1.Lines.Add('Impossible to open a socket')
  else Memo1.Lines.Add('Socket opened');
end;
(*---------------------------------------------------*)
function TForm1.INetAddr(Host: string): integer;
var
  pHost: PChar;
  HostEnt: PHostEnt;
begin
  if Host = '' then begin
    Result := INADDR_NONE;
  end else begin
    pHost := PChar(Host);
    Result := inet_addr(pHost);
    if Result = INADDR_NONE then begin
      HostEnt := gethostbyname(pHost);
      if HostEnt <> nil then Result := integer(pointer(HostEnt^.h_addr^)^);
    end;
  end;
end;
(*---------------------------------------------------*)
procedure TForm1.Button3Click(Sender: TObject);
begin
  WSAASyncSelect(fSocket, Handle, WM_USER, FD_CONNECT or FD_READ or FD_WRITE or FD_CLOSE);
end;
(*---------------------------------------------------*)
procedure TForm1.Button4Click(Sender: TObject);
var
  sa: TSockAddr;
begin
  FillChar(sa, SizeOf(sa), 0);
  sa.sin_family := AF_INET;
  sa.sin_addr.S_addr := INetAddr('145.70.16.5');
  sa.sin_port := htons(23);
  if connect(fSocket, sa, SizeOf(sa)) <> 0 then Memo1.Lines.add('Unable to connect to server')
  else Memo1.Lines.Add('Connection Established');
end;
(*---------------------------------------------------*)
procedure TForm1.Button5Click(Sender: TObject);
var request: String;
    result: Integer;
begin
        request:= 'Hello How Are You';
        result:= Send(fsocket, request[1], Length(request), 0);
        if result < 0
        then Memo1.Lines.Add('Message not Send')
        else Memo1.Lines.Add('Message Send');
end;
(*---------------------------------------------------*)

Peter


0
peterkiers
Asked:
peterkiers
  • 2
  • 2
1 Solution
 
Scay7Commented:
Hi man i also wanted to communicate betweensome programs using sock connections and TheRealLoki gave me this example :

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21810377.html

Works great im sure you can mod it to your needs...

Peace Scay7
0
 
peterkiersAuthor Commented:
mmm, thanks for the respons but I'm not exacly sure
what to do with it, and I only want to use the Winsock-unit
I don't want no component, The purpose of my code is to
get the text from the AS400-server.  

P.
0
 
Scay7Commented:
Okay hmm here or some links that might help but im sure that is
easier to use components that come standard with delphi...

But ye what ever... :P here are the links that helped me out a few times...


http://www.smartdata.com.au/delphi_isp/index.html
http://www.faqs.org/faqs/windows/winsock/programmer-faq/
http://forge.novell.com/modules/xfref_library/detail.php?reference_id=1029

http://www.hoerstemeier.com/tcpip.htm <-- this one looks promising...

peace Scay7
0
 
peterkiersAuthor Commented:
Pfff, I have been reading and trying for a week now, I know
now how to send a string or a file to a server, but supose I
don't want to send a file or string, but just getting the logon-
text of the server in my memo!. Just a connection to an AS400
-server and get the logon-text of the AS400 in my Memo.

When I use a ICS-component, and make a connection the server
I get this(an AS400-logon screen with language Dutch):

AANMELDING          
                                       Systeem . . . . . :   AS4SV007
                                        Subsysteem  . . . :   QINTER      
                                         Beeldstation  . . :   QPADEV0003

Gebruiker . . . . . . . . . . . .  
Wachtwoord  . . . . . . . . . . .
Programma/procedure . . . . . . .  
Menu  . . . . . . . . . . . . . .  
Actuele bibliotheek . . . . . . .  

 (C) COPYRIGHT IBM CORP. 1980, 2003.    


And I want this with Winsock (not with a component)!

Greetings and thank you in advanced.

Peter Kiers
                                 
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now