From 5e763216ee2c96c86898f8360e5de32a4fe5702d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 21 Jun 2012 16:22:17 +0000 Subject: [PATCH] 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 --- harbour/ChangeLog | 11 +++-- harbour/tests/ipclnt.prg | 32 +++++++++++++ harbour/tests/ipsvr.prg | 99 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 harbour/tests/ipclnt.prg create mode 100644 harbour/tests/ipsvr.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index dcd88e4fce..8314002613 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -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. diff --git a/harbour/tests/ipclnt.prg b/harbour/tests/ipclnt.prg new file mode 100644 index 0000000000..bf4b74633f --- /dev/null +++ b/harbour/tests/ipclnt.prg @@ -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 diff --git a/harbour/tests/ipsvr.prg b/harbour/tests/ipsvr.prg new file mode 100644 index 0000000000..45c5716df6 --- /dev/null +++ b/harbour/tests/ipsvr.prg @@ -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