Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Receiving Message Via TCP/IP And Port#
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00585789
Message ID:
00585842
Views:
18
>In our applications we have a need to receive information from an interface engine within a facility that contains patient information. The interface engine send a text string in HL7 format (just a long string) to a ip address and port number. Is there a way in VFP to create a "Listner" on a port # and trigger an event when a message is received?
>
>Thanks for any input?
>

Kirk,
You can use the Winsock ActiveX control to handle this. Listener example:
DEFINE CLASS form1 AS form

	Top = 0
	Left = 0
	Height = 99
	Width = 573
	DoCreate = .T.
	Caption = "Server"
	Name = "Form1"

	ADD OBJECT olecontrol1 AS olecontrol WITH ;
		Top = 12, ;
		Left = 12, ;
		Height = 100, ;
		Width = 100, ;
		Name = "Olecontrol1"

	ADD OBJECT label1 AS label WITH ;
		WordWrap = .T., ;
		Caption = "", ;
		Height = 36, ;
		Left = 156, ;
		Top = 12, ;
		Width = 384, ;
		Name = "Label1"

	ADD OBJECT olecontrol2 AS olecontrol WITH ;
		Top = 60, ;
		Left = 12, ;
		Height = 100, ;
		Width = 100, ;
		Name = "Olecontrol2"

	ADD OBJECT label2 AS label WITH ;
		Caption = "State:", ;
		Height = 24, ;
		Left = 48, ;
		Top = 12, ;
		Width = 60, ;
		Name = "Label2"

	ADD OBJECT label3 AS label WITH ;
		Caption = "Bytes Received:", ;
		Height = 17, ;
		Left = 48, ;
		Top = 72, ;
		Width = 180, ;
		Name = "Label3"

	PROCEDURE Init
		With THISFORM.Olecontrol1.Object
			.LocalPort = 1001  && or whatever port you want to listen to
			.Listen
		Endwith
	ENDPROC

	PROCEDURE olecontrol1.Error
		*** ActiveX Control Event ***
		LPARAMETERS number, description, scode, source, helpfile, helpcontext, canceldisplay
		wait window 'Server Error'+chr(13)+'Error: ' + transform(number)+chr(13)+'Description: ' + description
	ENDPROC

	PROCEDURE olecontrol1.ConnectionRequest
		*** ActiveX Control Event ***
		LPARAMETERS requestid
		With THISFORM
			.Olecontrol2.Accept(requestid)
			.Label2.Caption = 'State: ' + transform(.Olecontrol2.State)
		Endwith
	ENDPROC

	PROCEDURE olecontrol2.Error
		*** ActiveX Control Event ***
		LPARAMETERS number, description, scode, source, helpfile, helpcontext, canceldisplay
		wait window 'Server Error'+chr(13)+'Error: ' + transform(number)+;
			chr(13)+'Description: ' + description
	ENDPROC

	PROCEDURE olecontrol2.DataArrival
		*** ActiveX Control Event ***
		LPARAMETERS bytestotal
		local lcdata
		lcdata = ""
		THISFORM.Label3.Caption = 'Bytes received: '+transform(bytestotal)
		THIS.GetData(@lcdata)
		THISFORM.Label1.Caption = lcdata
	ENDPROC

	PROCEDURE olecontrol2.Close
		*** ActiveX Control Event ***
		THIS.Close
	ENDPROC

	PROCEDURE olecontrol2.Destroy
		THIS.Close
	ENDPROC
ENDDEFINE
The code above was generated by the Class browser from a Listener form I created. The OleControls were MSWinsock controls dropped onto the form.

HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Reply
Map
View

Click here to load this message in the networking platform