Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why does not work Mswinsck.ocx?
Message
 
 
To
22/05/2001 09:49:57
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00506724
Message ID:
00509931
Views:
133
I don't know why it works with Delphi. Here is a server form (generated using the Class browser so you may have to tweak it):
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
			.Listen
		Endwith
	ENDPROC

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

	PROCEDURE olecontrol2.DataArrival
		*** ActiveX Control Event ***
		LPARAMETERS bytestotal
		local lcdata
		lcdata = replicate(chr(0),200)
		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
Set the LocalPort of both Winsock controls in the property sheet (it didn't show up in code). The first instance of the Winsock listens and when it detects a ConnectionRequest, it tells the second control to Accept the incoming request. The first continues to Listen.

When data is sent, the second control's DataArrival event will fire and you then need to retrieve the data using GetData. You must pass a variable to the GetData method by reference to actually retrieve the data so you need the @ symbol. You don't need to allocate the initial space like I do with a 200 character string but I do. You only need to initialize it as a character string.

Note:
I added calls to the Close method in the Destroy and the Close events. The Destroy is called if the form goes away and the Winsock control is destroyed. It then closes itself. The Close event is fired if the connected client closes itself. If you don't have the proper calls to close Winsock, you will probably get lock ups in VFP.

HTH.

>Thank for the answer.
>
>>From the server:
>>ping < IP address of the client >
>Works - OK.
>
>>From the client:
>>ping < IP address of the server >
>Works perfectly.
>
>>If this works, you may have a problem witht he ports being used.
>>Try another ort.
>I tried a lot of other port. Outcome same.
>The method CONNECT for Mswinsck.ocx works instantaneously, but on former State=0.
>In what a problem?
>
>P.S.
>The test under Delphi with Mswinsck.ocx works perfectly.
Larry Miller
MCSD
LWMiller3@verizon.net

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

Click here to load this message in the networking platform