#include "fivewin.ch"
#define CHAR_START Chr(169)
#define CHAR_END Chr(168)
static oSocket
function Main()
local oWnd
DEFINE WINDOW oWnd
ACTIVATE WINDOW oWnd MAXIMIZED;
ON INIT Server();
VALID ( oSocket:End(), .t. )
return nil
function Server()
local oClient
oSocket = TSocket():New( 8083 )
oSocket:lDebug:= .t.
oSocket:cLogFile:="server.txt"
oSocket:bAccept = { | oSocket | oClient := TSocket():Accept( oSocket:nSocket ),;
oClient:bRead := { | oSocket | OnReadSocket( oSocket ) },;
oClient:bClose := { | oSocket | OnCloseSocket( oSocket)},;
oClient:lDebug:= .t., oClient:cLogfile:="client.txt" }
oSocket:Listen()
return nil
function OnReadSocket( oSocket )
local xPacket, nCor, cAck, n
xPacket := oSocket:GetData()
if left(xPacket ,1 ) == CHAR_START .AND. Right(xPacket ,1 ) == CHAR_END // DAT5
nCor := StrCharCount( xPacket, CHAR_END ) // cuenta las coordenadas
for n = 1 to nCor // extraemos las cordenadas y las reconocemos
cAck := Right( StrToken( xPacket, n , CHAR_END ), 4 )
oSocket:SendData(CHAR_START+ "|H1234567890ABC|E"+ cAck+ CHAR_END )
next
endif
if left(xPacket ,3 ) == "$AV" // AVL100
oSocket:SendData("$OK*04")
endif
SysRefresh()
return nil
///////////////////////////////////////////////
function OnCloseSocket( oSocket )
oSocket:End()
return nil
02/03/10 21:20:26: Accept Socket handle: 156
02/03/10 21:20:26: Write Socket handle: 276
02/03/10 21:20:26: Write Socket handle: 276
02/03/10 21:25:10: Accept Socket handle: 156
02/03/10 21:25:10: Write Socket handle: 276
02/03/10 21:25:10: Write Socket handle: 276
02/03/10 21:25:11: Read Socket handle: 276
02/03/10 21:25:21: Close Socket handle: 276
.
.
.
.
02/04/10 17:27:04: Read Socket handle: 304
02/04/10 17:29:05: Read Socket handle: 304
02/04/10 17:29:41: Accept Socket handle: 156
02/04/10 17:30:53: Close Socket handle: 304
...aquí se muere
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 6 guests