> SByteCount := TCPServer.Receive(@SBuffer, SizeOf(SBuffer) - 1); You call Receive on the server socket. Wrong. You have to call Receive on the client socket. Have a look at TcpSrv sample program.
Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be ----- Original Message ----- From: "S S" <[EMAIL PROTECTED]> To: <twsocket@elists.org> Sent: Tuesday, August 08, 2006 10:10 AM Subject: [twsocket] TWSocket Server receives -1 instead of receivinghexadecimal values (array) > Hi all, > > I am new to delphi.My application needs to act as client and send some commands to create notification channel to the host reader(IP 192.168.100.75/Port 1000, then receive the response from the host reader. > But before it sends commands to the host reader,it need to start the server at IP Address 192.168.100.1/Port 3000,so that once the commands for notification channel is executed,(my application) the server can receive the tags send by the reader. > > Ma application can successfully connect to the host reader as client and send the commands and receive the response.It can also create and connect to the server, > but The problem is,The server cannot receive any output from the reader client. > The SBuffer shows all 0 and SByteCount is -1. > I want to continously receive hexadecimal values from the reader. > > I am attaching a section of my code. > Please help.Needed it urgently > > > unit CAENUnit; > interface > uses > Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, > Dialogs, DynamicSkinForm, WSocket, WSocketS, StdCtrls, SkinBoxCtrls, > ExtCtrls, SkinCtrls, ComCtrls, ToolsUnit, StrUtils, DB, Grids, DBGrids, > dbisamtb, BaseGrid, AdvGrid, DBAdvGrid; > type > TTcpSrvClient = class(TWSocketClient) > public > RcvdLine : String; > ConnectTime : TDateTime; > end; > TCAENForm = class(TForm) > DynamicSkinForm: TspDynamicSkinForm; > LogSplitter: TspSkinSplitter; > LogGroupBox: TspSkinGroupBox; > LogMemo: TspSkinMemo; > LogScrollBar: TspSkinScrollBar; > TopPanel: TspSkinPanel; > TransponderGroupBox: TspSkinGroupBox; > TransponderVScrollBar: TspSkinScrollBar; > TransponderHScrollBar: TspSkinScrollBar; > UniqueGroupBox: TspSkinGroupBox; > TagDataSource: TDataSource; > UniqueTagsSplitter: TspSkinSplitter; > UniqueTagGrid: TDBAdvGrid; > TransponderListView: TspSkinListView; > CAENClientSocket: TWSocket; > procedure FormCreate(Sender: TObject); > procedure FormResize(Sender: TObject); > procedure TagDataSourceDataChange(Sender: TObject; Field: TField); > procedure FormShow(Sender: TObject); > procedure FormHide(Sender: TObject); > procedure CAENClientSocketSessionConnected(Sender: TObject; ErrCode: Word); > procedure CAENClientSocketDataAvailable(Sender: TObject; ErrCode: Word); > > private > { Private declarations } > ByteCount: integer; > Data: string; > TagId: string; > TagSetReceived: boolean; > IncomingTags: TStringList; > SBuffer: array[0..100000]of byte; > Buffer: array [0..1023] of byte; > CreateNotfTrgCmd: array [0..54] of byte; > CreateReadTrgCmd: array [0..53] of byte; > CreateNotfChnCmd: array [0..68] of byte; > AddSrcNotfChnCmd: array [0..52] of byte; > AddNotfTrgNotfChnCmd: array [0..58] of byte; > AddReadTrgSrcCmd: array [0..51] of byte; > //AddReadPtSrcCmd: array [0..8] of byte; > procedure TCPServerClientConnect(Sender: TObject; > Client: TWSocketClient; Error: Word); > procedure TCPServerClientDataAvailable(Sender: TObject; Error: Word); > public > { Public declarations } > SByteCount: integer; > Processing: boolean; > TCPServer: TWSocketServer; > ServerRunning: boolean; > procedure Display(msg: String); > procedure StartTCPServer; > procedure StopTCPServer; > procedure ClearWorkArea; > procedure ClearAllData; > procedure Connect; > procedure Close; > procedure SendCommand(command: Pointer; size: integer); > procedure Mainloop; > procedure ExecuteCommand; > end; > var > CAENForm: TCAENForm; > implementation > uses MainUnit; > {$R *.dfm} > > procedure TCAENForm.StartTCPServer; > begin > TCPServer := TWSocketServer.Create(nil); > TCPServer.Addr := '192.168.100.1'; > TCPServer.Port := '3000'; > TCPServer.Proto := 'tcp'; > TCPServer.LineMode := False; > //TCPServer.LineMode := True; > TCPServer.LineEcho := False; > TCPServer.LineEdit := False; > TCPServer.ClientClass := TTcpSrvClient; > TCPServer.Banner := ''; > TCPServer.onfiltered= TCPServerClientConnect; > TCPServer.onfiltered= TCPServerClientDataAvailable; > TCPServer.Listen; > end; > procedure TCAENForm.StopTCPServer; > begin > TCPServer.Close; > TCPServer.Free; > end; > procedure TCAENForm.Display(msg: String); > begin > LogMemo.Lines.BeginUpdate; > try > while LogMemo.Lines.Count > 200 do > LogMemo.Lines.Delete(0); > LogMemo.Lines.Insert(0,Msg); > finally > LogMemo.Lines.EndUpdate; > end; > end; > procedure TCAENForm.TCPServerClientConnect(Sender: TObject; > Client: TWSocketClient; Error: Word); > begin > with Client as TTcpSrvClient do begin > Display(#13#10'Client connected.' + > ' Remote: ' + PeerAddr + ':' + PeerPort + > ' Local: ' + GetXAddr + ':' + GetXPort); > {Display('There is now ' + > IntToStr(TWSocketServer(Sender).ClientCount) + > ' client(s) connected.');} > onfiltered= TCPServerClientDataAvailable; > Confiltered= Now; > end; > end; > procedure TCAENForm.TCPServerClientDataAvailable( > Sender : TObject; > Error : Word); > var > i: integer; > TagVisibleCount: string; > TagTimeStamp: TDateTime; > TagValid: boolean; > s: string; > begin > IncomingTags.Clear; > with Sender as TTcpSrvClient do begin > SByteCount := TCPServer.Receive(@SBuffer, SizeOf(SBuffer) - 1); > Display('No of TagBytes Received: '+ IntToStr(SByteCount)); > for i := 1 to SByteCount do > s := s + IntToHex(SBuffer[i],2); > Display ( s ); > end; > end; > > > > > --------------------------------- > Groups are talking. We´re listening. Check out the handy changes to Yahoo! Groups. > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://www.elists.org/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be