Can vfp realize such multi-threading program(winsock)?



Hi, everyone,
I want to write a winsocket system to transfer certain messages between two
remote computers.
Client transfers a data package to server part, and wait the response from
the server,
if server dispose the data package successful, then sends a ok message to
client.
if client gets this ok message, begin to do other part the program. the
following is part of the program:


In winsocket client:
&&Form has a commandbutton named send and a winsock olecontrol named
clientSock
&&TranOk is property of form, records whether a data package is disposed by
server successful

&&Click event of send commandbutton
#Define EOT Chr(4)+Chr(3) &&End of Text
#DEFINE EOFILE CHR(4)+CHR(6)+CHR(3) &&whether file has been transfered
successfully
#DEFINE SFILE CHR(6)+CHR(3)+CHR(4) &&whether transferring file
LOCAL lcFileName,lcStr,RetVal,fHand,lcFsize,lCnt,tCnt
With Thisform.ClientSock
If .state = 7 THEN
RetVal=GETFILE()
IF EMPTY(RetVal) THEN
RETURN
ENDIF
lcFileName=RIGHT(RetVal,LEN(RetVal)-RAT('\',RetVal))
ThisForm.Tranok =.F. && TranOk
.SendData(SFILE+lcFileName+EOT)&& No connection, no send

DO WHILE .T.
DOEVENTS
IF ThisForm.TranOk THEN
EXIT
ENDIF
INKEY(.01)
IF .Object.State<>7 THEN
WAIT WINDOW "Êý¾Ý´«ËÍ´íÎó!" NoWait
Return
ENDIF
ENDDO
&& do other code. if not ThisForm.TranOk, waitting in the before code
&&......
&&......
ENDWITH
&&End of Click Event

&&in dataArrival event of clientsock of clientform
Lparameters tnByteCount
#Define EOFILE Chr(4)+Chr(6)+Chr(3)
#Define EOT Chr(4)+Chr(3)
#Define FILEOK Chr(2)+Chr(6)+Chr(5)
Local lcBuffer
lcBuffer = Space(tnByteCount)

* This gets the data from the socket. It happens, that the data
* isn't received in a single rush. Thus we use a EOT (end of transmission)
* sign to be sure, the data is complete. Until we get this, the data is
stuffed
* into cRecieveBuffer.

This.GetData( @lcBuffer, , tnByteCount )
If Left(lcBuffer,3)=FILEOK Then && waitting for server transfers OK message,
&& if ok,do other code of click event of
send commandbutton
Thisform.tranOk=.T.
Return
Endif
&& end of dataArrival

In Winsock Server:

&&part of code in dataArrival of serverSock

Lparameters tnByteCount
#Define EOT Chr(4)+Chr(3)
#Define EOFILE Chr(4)+Chr(6)+Chr(3)
#Define SFILE Chr(6)+Chr(3)+Chr(4)
#Define FILEOK CHR(2)+CHR(6)+CHR(5)
Local lcBuffer,lcFhand
lcBuffer = Space(tnByteCount)
* This gets the data from the socket. It can happen, that the data isn't
* received in a single rush. Thus we need a EOT (end of transmission)
* sign to be sure, the data is complete. Until we get this, the data
* is stuffed into cReceiveBuffer.
INKEY(.01)
This.GetData( @lcBuffer, , tnByteCount )
IF ThisForm.SendFile Or LEFT(lcBuffer,3)=SFILE THEN

ThisForm.SendFile=.T.
IF LEFT(lcBuffer,3)=SFILE THEN
ThisForm.FileName=SUBSTR(lcBuffer,4)
IF RIGHT(ThisForm.FileName,2)=EOT THEN
ThisForm.FileName=LEFT(thisform.FileName,LEN(ThisForm.FileName)-2)
ENDIF
IF FILE(ADDBS(GETENV("TEMP"))+ThisForm.FileName) THEN
TRY
DELETE FILE (ADDBS(GETENV("TEMP"))+ThisForm.FileName)
CATCH
FINALLY
ENDTRY
ENDIF
This.sendData(FILEOK)
ELSE
IF NOT FILE(ADDBS(GETENV("TEMP"))+ThisForm.FileName) THEN
lcFhand=FCREATE(ADDBS(GETENV("TEMP"))+ThisForm.FileName)
ELSE
lcFhand=FOPEN(ADDBS(GETENV("TEMP"))+ThisForm.FileName,2)
ENDIF
IF Right(lcBuffer,3) <> EOFILE THEN
FWRITE(lcFhand,lcBuffer)
This.sendData(FILEOK)
ELSE
FWRITE(lcFhand,LEFT(lcBuffer,LEN(lcBuffer)-3))
This.sendData(FILEOK)
With Thisform.EditOut
.Value = .Value + "½ÓÊÕÎļþÒ»Îļþ³É¹¦"+thisform.filename + Chr(13) +
Chr(10)
ThisForm.SendFile=.F.
.Refresh()
Endwith
ENDIF
=FCLOSE(lcFhand)
ENDIF
ELSE
&&.....
ENDIF
&&.....

The problem is in client part of windows, if that thread is diposing sending
data package to server part, it won't have time to dispose dataArrival
events which indicates whether data transfer ok!
it always stay in:
DO WHILE .T.
DOEVENTS
IF ThisForm.TranOk THEN
EXIT
ENDIF
INKEY(.01)
IF .Object.State<>7 THEN
WAIT WINDOW "Êý¾Ý´«ËÍ´íÎó!" NoWait
Return
ENDIF
ENDDO
how can let cpu assign time to dispose dataArrival events of cliensock?

Any ideas is greatly appreciated!

Best Regards
Chuen


.