2012-06-21 12:22 UTC+0200 Viktor Szakats (harbour syenar.net)

+ tests/ipclnt.prg
  + tests/ipsvr.prg
    + added IP client/server example from Alex Strickland
This commit is contained in:
Viktor Szakats
2012-06-21 16:22:17 +00:00
parent 17385d0aba
commit 5e763216ee
3 changed files with 139 additions and 3 deletions

View File

@@ -16,6 +16,11 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-06-21 12:22 UTC+0200 Viktor Szakats (harbour syenar.net)
+ tests/ipclnt.prg
+ tests/ipsvr.prg
+ added IP client/server example from Alex Strickland
2012-06-20 19:57 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtcore/hbqt_bind.cpp
! Organized: tracelog entries.
@@ -38,7 +43,7 @@
* contrib/hbqt/qtgui/qth/QSlider.qth
* contrib/hbqt/qtgui/qth/QSystemTrayIcon.qth
* contrib/hbqt/qtgui/qth/QWindowStateChangeEvent.qth
! Fixed: wrong "else if" in constructors.
! Fixed: wrong "else if" in constructors.
Now all classes has been scanned for this regression.
Please report if you find something weired still.
@@ -46,8 +51,8 @@
* contrib/hbqt/qtcore/hbqt_bind.cpp
* contrib/hbqt/qtcore/qth/QLibraryInfo.qth
* contrib/hbqt/qtgui/qth/QDesktopServices.qth
! Implemented: mechanism to generate a Harbour level class
without the need of a Qt level object for those classes
! Implemented: mechanism to generate a Harbour level class
without the need of a Qt level object for those classes
where methods are executed by Qt code only.
This fixes the bug issue reported by Ligui.

32
harbour/tests/ipclnt.prg Normal file
View File

@@ -0,0 +1,32 @@
/*
* $Id$
*/
#include "common.ch"
#include "hbsocket.ch"
#define ADDRESS "127.0.0.1"
#define PORT 10000
#define EOT ( Chr( 4 ) )
PROCEDURE main()
LOCAL hSocket
IF Empty( hSocket := hb_socketOpen() )
? "socket create error " + hb_ntos( hb_socketGetError() )
ENDIF
IF ! hb_socketConnect( hSocket, { HB_SOCKET_AF_INET, ADDRESS, PORT } )
? "socket connect error " + hb_ntos( hb_socketGetError() )
ENDIF
? hb_socketSend( hSocket, "hi" + EOT )
? hb_socketSend( hSocket, "how" + EOT )
? hb_socketSend( hSocket, "you doing?" + EOT )
? hb_socketSend( hSocket, "quit" + EOT )
hb_socketShutdown( hSocket )
hb_socketClose( hSocket )
RETURN

99
harbour/tests/ipsvr.prg Normal file
View File

@@ -0,0 +1,99 @@
/*
* $Id$
*/
#include "common.ch"
#include "hbsocket.ch"
#define ADDRESS "0.0.0.0"
#define PORT 10000
#define EOT ( Chr( 4 ) )
#define TIMEOUT 3000 // 3s
REQUEST HB_MT
PROCEDURE main()
LOCAL hListen
LOCAL hSocket
IF ! hb_mtvm()
? "multithread support required"
RETURN
ENDIF
? "create listening socket"
IF Empty( hListen := hb_socketOpen() )
? "socket create error " + hb_ntos( hb_socketGetError() )
ENDIF
IF ! hb_socketBind( hListen, { HB_SOCKET_AF_INET, ADDRESS, PORT } )
? "bind error " + hb_ntos( hb_socketGetError() )
ENDIF
IF ! hb_socketListen( hListen )
? "listen error " + hb_ntos( hb_socketGetError() )
ENDIF
DO WHILE .T.
IF Empty( hSocket := hb_socketAccept( hListen, , TIMEOUT ) )
IF hb_socketGetError() == HB_SOCKET_ERR_TIMEOUT
? "loop"
ELSE
? "accept error " + hb_ntos( hb_socketGetError() )
ENDIF
ELSE
? "accept socket request"
hb_threadDetach( hb_threadStart( @process(), hSocket ) )
ENDIF
IF Inkey() == 27
? "quitting - esc pressed"
EXIT
ENDIF
ENDDO
? "close listening socket"
hb_socketShutdown( hListen )
hb_socketClose( hListen )
RETURN
PROCEDURE process( hSocket )
LOCAL cRequest
LOCAL nLen
LOCAL cBuf
DO WHILE .T.
cRequest := ""
nLen := 1
DO WHILE At( EOT, cRequest ) == 0 .AND. nLen > 0
cBuf := Space( 4096 )
IF ( nLen := hb_socketRecv( hSocket, @cBuf,,, 10000 ) ) > 0 /* Timeout */
cRequest += Left( cBuf, nLen )
ELSE
IF nLen == -1 .AND. hb_socketGetError() == HB_SOCKET_ERR_TIMEOUT
nLen := 0
ENDIF
ENDIF
ENDDO
IF nLen == - 1
? "recv() error:", hb_socketGetError()
ELSEIF nLen == 0
? "connection closed"
EXIT
ELSE
? cRequest
IF "quit" $ cRequest
? "exit"
EXIT
ENDIF
ENDIF
ENDDO
? "close socket"
hb_socketShutdown( hSocket )
hb_socketClose( hSocket )
RETURN