Good Morning , its me again.
On command line this sends the variables from across the network (client / server) Now i want to have the same application send from a command line to say a a form with a listview and display on the Listview.
I got very lost along the line as i have not done this sending from a command line to GUI , so this would be my first trial for something like that
Client Works fine , likewise Server .. But on
cmd.exe only but how can i send it now from the command line and have the values shown in the Listview. My code looks somewhat like this :
Client (Which gets the information for Display looks like this : ):
unit myclientUi;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls , Windows , Winsock;
type
{ TForm1 }
TForm1 = class(TForm)
ListView1: TListView;
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure ReceiveBuf();
var
_wsdata: WSAData;
serverSocket, S: TSocket;
_addrIn, _addr: sockaddr_in;
addrSize: Integer;
SendBuf:Array[0..31] of AnsiChar;
data : Integer;
begin
if WSAStartup(MakeWord(2, 2), _wsdata) <> 0 then
Exit;
serverSocket := socket(AF_INET, SOCK_STREAM, 0);
if serverSocket = INVALID_SOCKET then
Exit;
_addrIn.sin_family := AF_INET;
_addrIn.sin_addr.S_addr := INADDR_ANY;
_addrIn.sin_port := htons(8080);
if bind(serverSocket, _addrIn, SizeOf(_addrIn)) = SOCKET_ERROR then
Exit;
if listen(serverSocket, SOMAXCONN) = SOCKET_ERROR then
Exit;
addrSize := SizeOf(_addrIn);
getsockname(serverSocket, _addrIn, addrSize);
//Writeln(Format('Listening on port %d' + #13#10, [ntohs(_addrIn.sin_port)]));
while True do
begin
S := accept(serverSocket, @_addr, @addrSize);
if S <> INVALID_SOCKET then
begin
repeat
data := recv(s, SendBuf, SizeOf(SendBuf), 0);
if data > 0 then Writeln('Bytes Received: ' + IntToStr(data) + ' Text: ' +SendBuf); // I believe it should save into the Listview From here
until data <= 0;
closesocket(S);
end;
end;
end;
{ TForm1 }
end.
Now
Server which sends the information looks like this (Works 100% Fine)
program server;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes , SysUtils , Windows , Winsock
{ you can add units after this };
procedure SendBuf(Log: Array of AnsiChar);
var
MyData:WSADATA;
result:Integer;
s:TSocket;
clientservice:sockaddr_in;
BytesSent:Integer;
begin
try
result:= WSAStartup(MAKEWORD (2,2), MyData);
if result = NO_ERROR then
begin
s := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if s <> INVALID_SOCKET then
begin
clientservice.sin_family := AF_INET;
clientservice.sin_addr.s_addr := inet_addr('127.0.0.1');
clientservice.sin_port := htons(8080);
if connect(s,clientservice,sizeof(clientservice)) <> SOCKET_ERROR then
begin
bytesSent := send(s,Log,Length(Log),0);
writeln('Bytes send: ',bytesSent);
end else writeln('Failed to connect');;
end else writeln('Error at Socket: ',WSAGetLastError);;
end else writeln('Error at WSAStartup');
finally
Writeln(SysErrorMessage(GetLastError));
WSACleanUp;
Readln;
end;
end;
var
fullname : String;
telephone : String;
idNumber : String;
personInfo : Array[0..31] of AnsiChar;
begin
fullname := 'James Hall';
telephone := '+35798522360';
idNumber := 'H-986652300';
personInfo := fullname + ' ' + telephone + ' ' + idNumber;
SendBuf(personInfo);
end.
I dont know how to do this and hence i need some Clarity here for this. Anyone pls help.