procedure TForm1.Timer1Timer(Sender: TObject);
Var
T2,S: String;
Payload: String;
echars: String;
begin
{If Debug=True Then
Begin
s:=ReadText;
if s<>'' Then
Begin
form1.memo1.lines.add(s);
Exit;
End;
End;}
{ if pos('Debug:',s)>0 then
Begin
Delete(S,1,6);
T2:=Copy(s,1,pos('/',s)-1);
form1.memo1.lines.add(t2);
Exit;
End;}
If ConnX=True Then
Begin
If Tmp<>'' Then
Begin
S:=Tmp+ReadText;
tmp:='';
End
else
S:=ReadText;
if ScanIt('&&',S)>1 Then
Begin
T2:=S;
T2:=Copy(T2,1,Pos('&&',T2)+1);
Delete(s,1,Length(T2));
Tmp:=Tmp+s;
S:=T2;
End;
Echars:=Copy(S,Length(S)-1,2);
if (Echars<>'&&') and (S<>'') Then
Begin
tmp:=tmp+S;
S:='';
End;
If S<>'' Then
Begin
// Memo1.lines.add(s);
Begin
Payload:=S;
If Pos('&&',PayLoad)>0 Then
PayLoad:=Copy(Payload,1,Length(Payload)-2);
Delete(PayLoad,1,3);
if Copy(S,1,2)='$' Then
Begin
Memo1.lines.add(PayLoad);
//$1 = Host
//$2 = Port
//$3 = Connect
//$4 = Disconnect
//$5 = Payload For Remote Client
//$6 = Test Packet
Case S[3] Of
'1': RemoteHost:=Payload;
'2': RemotePort:=StrToInt(PayLoad);
'3':
Begin
Form1.ClientSocket1.Host:=RemoteHost;
Form1.ClientSocket1.Port:=RemotePort;
Form1.ClientSocket1.Active:=True;
Form1.Memo1.Lines.add('Establishing Connection To: '+RemoteHost+' Port: '+IntToStr(RemotePort));
// Debug:=True;
End;
'4': Form1.ClientSocket1.Active:=False;
'5': Form1.ClientSocket1.Socket.SendText(PayLoad);
End;
End;
End;
// if Form1.ClientSocket1.active=True Then
// ClientSocket1.Socket.SendText(S); //send it to the server from arduino
End;
End;
end;
Client side, this is how I dealt with the packet chunking (buffering issue) and that's to simply get what's known to be a full packet length up to &&
and any data left over gets put into a global temp buffer, and on the next read, the new data is appended onto the old tmp packet..
I just about got my head around this in Pascal, fat chance i'd be able to code something similar in C++ - i'm hoping someone else can so i can
make the changes client side to speed / optimize it.