I invocker Active Member Feb 23, 2020 #1 Hi I need A simple example to send and receive string from tcp server delphi to tcp client B4A
I invocker Active Member Feb 24, 2020 #2 client Code: socket.Initialize("socket") socket.Connect("127.0.0.1",1900,0) astream.InitializePrefix(socket.InputStream,True,socket.OutputStream,"astream") // ***************** Code: Private Sub astream_NewData (Buffer() As Byte) Dim strAs String = BytesToString(Buffer,0,Buffer.Length,"UTF8") Select Case str Case "TMSG" ToastMessageShow("TMSG",True) End Select ' Log( str) End Sub server delphi Code: procedure TForm1.IdTCPServer1Execute(AContext: TIdContext); var str: string; begin str := AContext.Connection.IOHandler.AllData(); if str <> EmptyStr then begin AContext.Connection.IOHandler.WriteLn('TMSG'); // do something with received string s end; end; Last edited: Feb 24, 2020 Upvote 0
client Code: socket.Initialize("socket") socket.Connect("127.0.0.1",1900,0) astream.InitializePrefix(socket.InputStream,True,socket.OutputStream,"astream") // ***************** Code: Private Sub astream_NewData (Buffer() As Byte) Dim strAs String = BytesToString(Buffer,0,Buffer.Length,"UTF8") Select Case str Case "TMSG" ToastMessageShow("TMSG",True) End Select ' Log( str) End Sub server delphi Code: procedure TForm1.IdTCPServer1Execute(AContext: TIdContext); var str: string; begin str := AContext.Connection.IOHandler.AllData(); if str <> EmptyStr then begin AContext.Connection.IOHandler.WriteLn('TMSG'); // do something with received string s end; end;
Erel B4X founder Staff member Licensed User Longtime User Feb 24, 2020 #3 Please use [code]code here...[/code] tags when posting code. Start with this video tutorial and examples: https://www.b4x.com/android/forum/threads/b4x-network-asyncstreams-b4xserializator.72149/#content Run the B4J and B4A examples. Upvote 0
Please use [code]code here...[/code] tags when posting code. Start with this video tutorial and examples: https://www.b4x.com/android/forum/threads/b4x-network-asyncstreams-b4xserializator.72149/#content Run the B4J and B4A examples.
Erel B4X founder Staff member Licensed User Longtime User Feb 24, 2020 #5 Best solution is to use B4J. You will need to find out the exact protocol that your delphi code expects. You cannot use B4XSerializator with Delphi. Search for AsyncStreamsText if you want to send and receive strings that end with 'end of line' chars. Upvote 0
Best solution is to use B4J. You will need to find out the exact protocol that your delphi code expects. You cannot use B4XSerializator with Delphi. Search for AsyncStreamsText if you want to send and receive strings that end with 'end of line' chars.
DonManfred Expert Licensed User Longtime User Feb 24, 2020 #6 Can you provide an example exe which implements such a server which i can start/stop on my PC? Maybe with a memo for the incoming messages and a edit to send something or so. Upvote 0
Can you provide an example exe which implements such a server which i can start/stop on my PC? Maybe with a memo for the incoming messages and a edit to send something or so.
I invocker Active Member Feb 24, 2020 #7 I change It to astream.Initialize(socket.InputStream,True,socket.OutputStream,"astream") and it work Thank's Upvote 0
I change It to astream.Initialize(socket.InputStream,True,socket.OutputStream,"astream") and it work Thank's