I am trying to test sending records from a utility to my app, which should receive and process the records.
I am able to send the record from my test utility with this code: procedure TForm10.btnSendMsgAsRecordClick(Sender: TObject); begin InitializeWSocketProperties; WSocket_AsClient.Connect; end; procedure TForm10.InitializeWSocketProperties; begin WSocket_AsClient.Addr := '10.172.2.93'; { TODO : After testing, read these vals from an .INI file } WSocket_AsClient.Port := '1234'; end; {== After connecting, this event is called ==} procedure TForm10.WSocket_AsClientSessionConnected(Sender: TObject; ErrCode: Word); begin if ErrCode <> 0 then begin ShowMessage(Format('Error in OnSessionConnected() event: %d', [ErrCode])); Exit; end; SendTheCurrentRecord; end; procedure TForm10.SendTheCurrentRecord; begin if cmbxMsgType.Items[cmbxMsgType.ItemIndex] = 'ACTIVATE_BOF_SORT' then SendActiv8BOFSortRecord //This is the one I'm testing . . . procedure TForm10.SendActiv8BOFSortRecord; var X: PActivateBOFSort; Ptr: PByte; iSent, iSize, iErrorCode: Integer; begin iSize := SizeOf(TActivateBOFSort); X := AllocMem(iSize); X^.OpCode := ACTIVATE_BOF_SORT; X^.Carrier := StrToIntDef(edt1.Text, 0); StrLCopy(X^.BOFSortLabel, PChar(edt2.Text), BOF_SORT_LABEL_LENGTH); X^.WorkstationOffset := StrToIntDef(edt3.Text, 0); X^.RecordTerminator := '~'; Ptr := PByte(X); while iSize > 0 do begin iSent := WSocket_AsClient.Send(Ptr, iSize); if iSent > 0 then begin Inc(Ptr, iSent); Dec(iSize, iSent); Continue; end; if iSent = 0 then begin ClientSocket.Close; raise Exception.Create('Connection closed gracefully'); end; iErrorCode := WSAGetLastError; if iErrorCode <> WSAEWOULDBLOCK then raise Exception.CreateFmt('Socket Error: %d', [iErrorCode]); end; --and in my "real" app the SessionAvailable() handler is fired, but the SessionConnected() does not, nor does OnDataAvailable(). What am I missing here? What necessary step am I leaving out? I have this code (adapted from one of the ICS demo apps) in the OnSessionAvailable() handler of my receiving app: procedure TfClientMain.WSocket_AsServerSessionAvailable(Sender: TObject; ErrCode: Word); var NewHSocket : TSocket; Peer : String; begin { We need to accept the client connection } NewHSocket := WSocket_AsServer.Accept; { And then associate this connection with our client socket } WSocket_AsClient.Dup(NewHSocket); end; ...and this code in OnSessionConnected(), but it doesn't get reached (also taken from some code gleaned from the mailing list): procedureTfClientMain.WSocket_AsServerSessionConnected(Sender: TObject; ErrCode: Word); begin ICS_RdPtr := 0; ICS_WrPtr := 0; if ICS_BufferSize = 0 then begin ICS_BufferSize := ICS_BUFFER_SIZE; ReAllocMem(ICS_Buffer, ICS_BufferSize); end; end; ...and this preliminary code in OnDataAvailable(), which also is not getting reached: procedure TfClientMain.WSocket_AsServerDataAvailable(Sender: TObject; ErrCode: Word); var sIncomingDataAsString: String; begin if ErrCode <> 0 then begin ClientDM.InsertException( CurrentUser, Format(sErrorNInWSocket_AsServerDataAvailable, [ErrCode]), GetHostNameOrDefaultIPAddress); Exit; end; sIncomingDataAsString := WSocket_AsServer.ReceiveStr; ShowMessage(sIncomingDataAsString); end; Again, what am I missing here? What necessary step am I leaving out or what basic concept do I not understand? I've been struggling with sending data via sockets for several days now. I've given up on the deprecated TClientSocket and TServerSocket components, and am quite frustrated at this point. Does it really have to be this hard to implement?
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. If the reader of this message is not the intended recipient, you are hereby notified that your access is unauthorized, and any review, dissemination, distribution or copying of this message including any attachments is strictly prohibited. If you are not the intended recipient, please contact the sender and delete the material from any computer.
-- 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