diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ad220e --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json + +### Global ### +*.exe \ No newline at end of file diff --git a/Donate/QR-Github-Paypal.png b/Donate/QR-Github-Paypal.png new file mode 100644 index 0000000..301fbc8 Binary files /dev/null and b/Donate/QR-Github-Paypal.png differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3fc4709 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Jiowcl + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/PureBasicNanoMsg/Core/Enums.pbi b/PureBasicNanoMsg/Core/Enums.pbi new file mode 100644 index 0000000..e976aa4 --- /dev/null +++ b/PureBasicNanoMsg/Core/Enums.pbi @@ -0,0 +1,224 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +; Version Macros for Compile-time API Version Detection +#NN_VERSION_CURRENT = 6 +#NN_VERSION_REVISION = 0 +#NN_VERSION_AGE = 1 + +; Socket Types +#NN_PROTO_REQREP = 3 +#NN_REQ = #NN_PROTO_REQREP * 16 + 0 +#NN_REP = #NN_PROTO_REQREP * 16 + 1 + +#NN_REQ_RESEND_IVL = 1 + +#NN_PROTO_PUBSUB = 2 +#NN_PUB = #NN_PROTO_PUBSUB * 16 + 0 +#NN_SUB = #NN_PROTO_PUBSUB * 16 + 1 +#NN_SUB_SUBSCRIBE = 1 +#NN_SUB_UNSUBSCRIBE = 2 + +; SP Address Families +#AF_SP = 1 +#AF_SP_RAW = 2 + +#NN_TCP = -3 +#NN_TCP_NODELAY = 1 + +; Max Size of an SP Address +#NN_SOCKADDR_MAX = 128 + +; Socket Option Levels +#NN_SOL_SOCKET = 0 + +; Socket Options (NN_SOL_SOCKET level) +#NN_LINGER = 1 +#NN_SNDBUF = 2 +#NN_RCVBUF = 3 +#NN_SNDTIMEO = 4 +#NN_RCVTIMEO = 5 +#NN_RECONNECT_IVL = 6 +#NN_RECONNECT_IVL_MAX = 7 +#NN_SNDPRIO = 8 +#NN_RCVPRIO = 9 +#NN_SNDFD = 10 +#NN_RCVFD = 11 +#NN_DOMAIN = 12 +#NN_PROTOCOL = 13 +#NN_IPV4ONLY = 14 +#NN_SOCKET_NAME = 15 +#NN_RCVMAXSIZE = 16 +#NN_MAXTTL = 17 + +; Message Options +#NN_DONTWAIT = 1 + +; Ancillary Data +#PROTO_SP = 1 +#SP_HDR = 1 + +; Socket Mutliplexing Support +#NN_POLLIN = 1 +#NN_POLLOUT = 2 + +; Transport Statistics +#NN_STAT_ESTABLISHED_CONNECTIONS = 101 +#NN_STAT_ACCEPTED_CONNECTIONS = 102 +#NN_STAT_DROPPED_CONNECTIONS = 103 +#NN_STAT_BROKEN_CONNECTIONS = 104 +#NN_STAT_CONNECT_ERRORS = 105 +#NN_STAT_BIND_ERRORS = 106 +#NN_STAT_ACCEPT_ERRORS = 107 + +#NN_STAT_CURRENT_CONNECTIONS = 201 +#NN_STAT_INPROGRESS_CONNECTIONS = 202 +#NN_STAT_CURRENT_EP_ERRORS = 203 + +; The Socket-internal Statistics +#NN_STAT_MESSAGES_SENT = 301 +#NN_STAT_MESSAGES_RECEIVED = 302 +#NN_STAT_BYTES_SENT = 303 +#NN_STAT_BYTES_RECEIVED = 304 + +; Protocol Statistics +#NN_STAT_CURRENT_SND_PRIORITY = 401 + +; Errors +#NN_HAUSNUMERO = 156384712 + +CompilerIf Not Defined(ENOTSUP, #PB_Constant) + #ENOTSUP = #NN_HAUSNUMERO + 1 +CompilerEndIf + +CompilerIf Not Defined(EPROTONOSUPPORT, #PB_Constant) + #EPROTONOSUPPORT = #NN_HAUSNUMERO + 2 +CompilerEndIf + +CompilerIf Not Defined(ENOBUFS, #PB_Constant) + #ENOBUFS = #NN_HAUSNUMERO + 3 +CompilerEndIf + +CompilerIf Not Defined(ENETDOWN, #PB_Constant) + #ENETDOWN = #NN_HAUSNUMERO + 4 +CompilerEndIf + +CompilerIf Not Defined(EADDRINUSE, #PB_Constant) + #EADDRINUSE = #NN_HAUSNUMERO + 5 +CompilerEndIf + +CompilerIf Not Defined(EADDRNOTAVAIL, #PB_Constant) + #EADDRNOTAVAIL = #NN_HAUSNUMERO + 6 +CompilerEndIf + +CompilerIf Not Defined(ECONNREFUSED, #PB_Constant) + #ECONNREFUSED = #NN_HAUSNUMERO + 7 +CompilerEndIf + +CompilerIf Not Defined(EINPROGRESS, #PB_Constant) + #EINPROGRESS = #NN_HAUSNUMERO + 8 +CompilerEndIf + +CompilerIf Not Defined(ENOTSOCK, #PB_Constant) + #ENOTSOCK = #NN_HAUSNUMERO + 9 +CompilerEndIf + +CompilerIf Not Defined(EAFNOSUPPORT, #PB_Constant) + #EAFNOSUPPORT = #NN_HAUSNUMERO + 10 +CompilerEndIf + +CompilerIf Not Defined(EPROTO, #PB_Constant) + #EPROTO = #NN_HAUSNUMERO + 11 +CompilerEndIf + +CompilerIf Not Defined(EAGAIN , #PB_Constant) + #EAGAIN = #NN_HAUSNUMERO + 12 +CompilerEndIf + +CompilerIf Not Defined(EBADF , #PB_Constant) + #EBADF = #NN_HAUSNUMERO + 13 +CompilerEndIf + +CompilerIf Not Defined(EINVAL , #PB_Constant) + #EINVAL = #NN_HAUSNUMERO + 14 +CompilerEndIf + +CompilerIf Not Defined(EMFILE , #PB_Constant) + #EMFILE = #NN_HAUSNUMERO + 15 +CompilerEndIf + +CompilerIf Not Defined(EFAULT , #PB_Constant) + #EFAULT = #NN_HAUSNUMERO + 16 +CompilerEndIf + +CompilerIf Not Defined(EACCES , #PB_Constant) + #EACCES = #NN_HAUSNUMERO + 17 +CompilerEndIf + +CompilerIf Not Defined(ENETRESET , #PB_Constant) + #ENETRESET = #NN_HAUSNUMERO + 18 +CompilerEndIf + +CompilerIf Not Defined(ENETUNREACH , #PB_Constant) + #ENETUNREACH = #NN_HAUSNUMERO + 19 +CompilerEndIf + +CompilerIf Not Defined(EHOSTUNREACH , #PB_Constant) + #EHOSTUNREACH = #NN_HAUSNUMERO + 20 +CompilerEndIf + +CompilerIf Not Defined(ENOTCONN , #PB_Constant) + #ENOTCONN = #NN_HAUSNUMERO + 21 +CompilerEndIf + +CompilerIf Not Defined(EMSGSIZE , #PB_Constant) + #EMSGSIZE = #NN_HAUSNUMERO + 22 +CompilerEndIf + +CompilerIf Not Defined(ETIMEDOUT , #PB_Constant) + #ETIMEDOUT = #NN_HAUSNUMERO + 23 +CompilerEndIf + +CompilerIf Not Defined(ECONNABORTED , #PB_Constant) + #ECONNABORTED = #NN_HAUSNUMERO + 24 +CompilerEndIf + +CompilerIf Not Defined(ECONNRESET , #PB_Constant) + #ECONNRESET = #NN_HAUSNUMERO + 25 +CompilerEndIf + +CompilerIf Not Defined(ENOPROTOOPT , #PB_Constant) + #ENOPROTOOPT = #NN_HAUSNUMERO + 26 +CompilerEndIf + +CompilerIf Not Defined(EISCONN , #PB_Constant) + #EISCONN = #NN_HAUSNUMERO + 27 +CompilerEndIf + +CompilerIf Not Defined(ESOCKTNOSUPPORT , #PB_Constant) + #ESOCKTNOSUPPORT = #NN_HAUSNUMERO + 28 +CompilerEndIf + +; Native Nanomsg Error Codes +#ETERM = #NN_HAUSNUMERO + 53 +#EFSM = #NN_HAUSNUMERO + 54 + +; Structure +Structure ZmqMsgT + _.b[64] +EndStructure + +; Callback Function +;PrototypeC NnThreadFnProc(vData.i) +;PrototypeC NnFreeFnProc(vData.i, vHint.i) +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 88 +; FirstLine = 70 +; Folding = ----- +; EnableXP +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField4 = 1.0.0 \ No newline at end of file diff --git a/PureBasicNanoMsg/Core/LibDll.pbi b/PureBasicNanoMsg/Core/LibDll.pbi new file mode 100644 index 0000000..3dc8d73 --- /dev/null +++ b/PureBasicNanoMsg/Core/LibDll.pbi @@ -0,0 +1,38 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +; Function Declare +Declare.i NnDllOpen(lpszDllPath.s) +Declare.i NnDllClose(dllInstance.i) + +; +; NnDllOpen +; +; +; Returns integer. +Procedure.i NnDllOpen(lpszDllPath.s) + ProcedureReturn OpenLibrary(#PB_Any, lpszDllPath) +EndProcedure + +; +; NnDllClose +; +; +; Returns integer. +Procedure.i NnDllClose(dllInstance.i) + If IsLibrary(dllInstance) + CloseLibrary(dllInstance) + EndIf + + ProcedureReturn #True +EndProcedure +; IDE Options = PureBasic 5.72 (Windows - x86) +; CursorPosition = 11 +; Folding = - +; EnableXP +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField4 = 1.0.0 \ No newline at end of file diff --git a/PureBasicNanoMsg/Core/Nanomsg.pbi b/PureBasicNanoMsg/Core/Nanomsg.pbi new file mode 100644 index 0000000..681d1a7 --- /dev/null +++ b/PureBasicNanoMsg/Core/Nanomsg.pbi @@ -0,0 +1,18 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +XIncludeFile "LibDll.pbi" +XIncludeFile "Enums.pbi" +XIncludeFile "Runtime.pbi" +XIncludeFile "Socket.pbi" + +; TODO +; IDE Options = PureBasic 5.72 (Windows - x64) +; CursorPosition = 10 +; EnableXP +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField4 = 1.0.0 \ No newline at end of file diff --git a/PureBasicNanoMsg/Core/NanomsgWrapper.pbi b/PureBasicNanoMsg/Core/NanomsgWrapper.pbi new file mode 100644 index 0000000..d7fd6d8 --- /dev/null +++ b/PureBasicNanoMsg/Core/NanomsgWrapper.pbi @@ -0,0 +1,209 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +CompilerIf #PB_Compiler_Version < 520 + CompilerWarning "PureBasic 5.2.0 Version Required." +CompilerEndIf + +; Declare Module NanomsgWrapper +DeclareModule NanomsgWrapper + Global dllInstance.i + + Declare.i DllOpen(lpszDllPath.s) + Declare.i DllClose() +EndDeclareModule + +; Declare Module NanomsgRuntime +DeclareModule NanomsgRuntime + Declare.i Errno() + Declare.s Strerror(errnum.i) + Declare.s Symbol(index.i, *value.Long) +EndDeclareModule + +; Declare Module NanomsgSocket +DeclareModule NanomsgSocket + Declare.i Socket(domain.i, protocol.i) + Declare.i Close(socket.i) + Declare.i Setsockopt(socket.i, level.i, option.i, optval.s, optvallen.i) + Declare.i Getsockopt(socket.i, level.i, option.i, *optval, optvallen.i) + Declare.i Bind(socket.i, addr.s) + Declare.i Connect(socket.i, addr.s) + Declare.i Shutdown(socket.i, how.i) + Declare.i Send(socket.i, buf.s, len.i, flags.i) + Declare.i Recv(socket.i, *buf, len.i, flags.i) +EndDeclareModule + +; Module NanomsgWrapper +Module NanomsgWrapper + IncludeFile "LibDll.pbi" + + ; + ; DllOpen + ; + ; + ; Returns integer. + Procedure.i DllOpen(lpszDllPath.s) + If IsLibrary(dllInstance) + ProcedureReturn dllInstance + EndIf + + dllInstance = NnDllOpen(lpszDllPath) + + ProcedureReturn dllInstance + EndProcedure + + ; + ; DllClose + ; + ; + ; Returns integer. + Procedure.i DllClose() + ProcedureReturn NnDllClose(dllInstance) + EndProcedure +EndModule + +; Module NanomsgRuntime +Module NanomsgRuntime + IncludeFile "Runtime.pbi" + + ; + ; Errno + ; + ; Returns integer. + Procedure.i Errno() + ProcedureReturn NnErrno(NanomsgWrapper::dllInstance) + EndProcedure + + ; + ; Strerror + ; + ; + ; Returns string. + Procedure.s Strerror(errnum.i) + ProcedureReturn NnStrerror(NanomsgWrapper::dllInstance, errnum) + EndProcedure + + ; + ; Symbol + ; + ; + ; + ; Returns string. + Procedure.s Symbol(index.i, *value.Long) + ProcedureReturn NnSymbol(NanomsgWrapper::dllInstance, index, *value) + EndProcedure +EndModule + +; Module NanomsgSocket +Module NanomsgSocket + IncludeFile "Socket.pbi" + + UseModule NanomsgWrapper + + ; + ; Socket + ; + ; + ; + ; Returns integer. + Procedure.i Socket(domain.i, protocol.i) + ProcedureReturn NnSocket(NanomsgWrapper::dllInstance, domain, protocol) + EndProcedure + + ; + ; Close + ; + ; + ; Returns integer. + Procedure.i Close(socket.i) + ProcedureReturn NnClose(NanomsgWrapper::dllInstance, socket) + EndProcedure + + ; + ; Setsockopt + ; + ; + ; + ; + ; + ; + ; Returns integer. + Procedure.i Setsockopt(socket.i, level.i, option.i, optval.s, optvallen.i) + ProcedureReturn NnSetsockopt(NanomsgWrapper::dllInstance, socket, level, option, optval, optvallen) + EndProcedure + + ; + ; Getsockopt + ; + ; + ; + ; + ; + ; + ; Returns integer. + Procedure.i Getsockopt(socket.i, level.i, option.i, *optval, optvallen.i) + ProcedureReturn NnGetsockopt(NanomsgWrapper::dllInstance, socket, level, option, *optval, optvallen) + EndProcedure + + ; + ; Bind + ; + ; + ; + ; Returns integer. + Procedure.i Bind(socket.i, addr.s) + ProcedureReturn NnBind(NanomsgWrapper::dllInstance, socket, addr) + EndProcedure + + ; + ; Connect + ; + ; + ; + ; Returns integer. + Procedure.i Connect(socket.i, addr.s) + ProcedureReturn NnConnect(NanomsgWrapper::dllInstance, socket, addr) + EndProcedure + + ; + ; Shutdown + ; + ; + ; + ; Returns integer. + Procedure.i Shutdown(socket.i, how.i) + ProcedureReturn NnShutdown(NanomsgWrapper::dllInstance, socket, how) + EndProcedure + + ; + ; Send + ; + ; + ; + ; + ; + ; Returns integer. + Procedure.i Send(socket.i, buf.s, len.i, flags.i) + ProcedureReturn NnSend(NanomsgWrapper::dllInstance, socket, buf, len, flags) + EndProcedure + + ; + ; Recv + ; + ; + ; + ; + ; + ; Returns integer. + Procedure.i Recv(socket.i, *buf, len.i, flags.i) + ProcedureReturn NnRecv(NanomsgWrapper::dllInstance, socket, *buf, len, flags) + EndProcedure +EndModule +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 200 +; FirstLine = 146 +; Folding = ---- +; EnableXP +; DPIAware \ No newline at end of file diff --git a/PureBasicNanoMsg/Core/Runtime.pbi b/PureBasicNanoMsg/Core/Runtime.pbi new file mode 100644 index 0000000..bc3dd29 --- /dev/null +++ b/PureBasicNanoMsg/Core/Runtime.pbi @@ -0,0 +1,88 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +; Prototype Function +PrototypeC.i NnErrnoFunc() +PrototypeC.i NnStrerrorFunc(errnum.i) +PrototypeC.i NnSymbolFunc(index.i, *value.Long) + +; Zmq Function Declare + +; +; NnErrno +; +; +; Returns integer. +Procedure.i NnErrno(dllInstance.i) + Protected.i lResult + Protected.NnErrnoFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_errno") + + If pFuncCall > 0 + lResult = pFuncCall() + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnStrerror +; +; +; +; Returns string. +Procedure.s NnStrerror(dllInstance.i, errnum.i) + Protected.s lResult + Protected.NnStrerrorFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_strerror") + + If pFuncCall > 0 + lResult = PeekS(pFuncCall(errnum), -1, #PB_UTF8) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnSymbol +; +; +; +; +; Returns string. +Procedure.s NnSymbol(dllInstance.i, index.i, *value.Long) + Protected.s lResult + Protected.NnSymbolFunc pFuncCall + Protected.i lNnSymbolResult + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_symbol") + + If pFuncCall > 0 + lNnSymbolResult = pFuncCall(index, *value) + + If lNnSymbolResult > 0 + lResult = PeekS(lNnSymbolResult, -1, #PB_UTF8) + EndIf + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 72 +; FirstLine = 22 +; Folding = - +; EnableXP +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField4 = 1.0.0 \ No newline at end of file diff --git a/PureBasicNanoMsg/Core/Socket.pbi b/PureBasicNanoMsg/Core/Socket.pbi new file mode 100644 index 0000000..5b6a9ff --- /dev/null +++ b/PureBasicNanoMsg/Core/Socket.pbi @@ -0,0 +1,233 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +; Prototype Function +PrototypeC.i NnSocketFunc(domain.i, protocol.i) +PrototypeC.i NnCloseFunc(socket.i) +PrototypeC.i NnSetsockoptFunc(socket.i, level.i, option.i, optval.p-Ascii, optvallen.i) +PrototypeC.i NnGetsockoptFunc(socket.i, level.i, option.i, *optval.p-Ascii, optvallen.i) +PrototypeC.i NnBindFunc(socket.i, addr.p-Ascii) +PrototypeC.i NnConnectFunc(socket.i, addr.p-Ascii) +PrototypeC.i NnShutdownFunc(socket.i, how.i) +PrototypeC.i NnSendFunc(socket.i, buf.p-Ascii, leng.i, flags.i) +PrototypeC.i NnRecvFunc(socket.i, *buf.p-Ascii, len.i, flags.i) + +; Nanomsg Function Declare + +; +; NnSocket +; +; +; +; +; Returns integer. +Procedure.i NnSocket(dllInstance.i, domain.i, protocol.i) + Protected.i lResult + Protected.NnSocketFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_socket") + + If pFuncCall > 0 + lResult = pFuncCall(domain, protocol) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnClose +; +; +; +; Returns integer. +Procedure.i NnClose(dllInstance.i, socket.i) + Protected.i lResult + Protected.NnCloseFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_close") + + If pFuncCall > 0 + lResult = pFuncCall(socket) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnSetsockopt +; +; +; +; +; +; +; +; Returns integer. +Procedure.i NnSetsockopt(dllInstance.i, socket.i, level.i, option.i, optval.s, optvallen.i) + Protected.i lResult + Protected.NnSetsockoptFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_setsockopt") + + If pFuncCall > 0 + lResult = pFuncCall(socket, level, option, optval, optvallen) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnGetsockopt +; +; +; +; +; +; +; +; Returns integer. +Procedure.i NnGetsockopt(dllInstance.i, socket.i, level.i, option.i, *optval, optvallen.i) + Protected.i lResult + Protected.NnGetsockoptFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_getsockopt") + + If pFuncCall > 0 + lResult = pFuncCall(socket, level, option, *optval, optvallen) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnBind +; +; +; +; +; Returns integer. +Procedure.i NnBind(dllInstance.i, socket.i, addr.s) + Protected.i lResult + Protected.NnBindFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_bind") + + If pFuncCall > 0 + lResult = pFuncCall(socket, addr) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnConnect +; +; +; +; +; Returns integer. +Procedure.i NnConnect(dllInstance.i, socket.i, addr.s) + Protected.i lResult + Protected.NnConnectFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_connect") + + If pFuncCall > 0 + lResult = pFuncCall(socket, addr) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnShutdown +; +; +; +; +; Returns integer. +Procedure.i NnShutdown(dllInstance.i, socket.i, how.i) + Protected.i lResult + Protected.NnShutdownFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_shutdown") + + If pFuncCall > 0 + lResult = pFuncCall(socket, how) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnSend +; +; +; +; +; +; +; Returns integer. +Procedure.i NnSend(dllInstance.i, socket.i, buf.s, len.i, flags.i) + Protected.i lResult + Protected.NnSendFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_send") + + If pFuncCall > 0 + lResult = pFuncCall(socket, buf, len, flags) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure + +; +; NnRecv +; +; +; +; +; +; +; Returns integer. +Procedure.i NnRecv(dllInstance.i, socket.i, *buf.String, len.i, flags.i) + Protected.i lResult + Protected.NnRecvFunc pFuncCall + + If IsLibrary(dllInstance) + pFuncCall = GetFunction(dllInstance, "nn_recv") + + If pFuncCall > 0 + lResult = pFuncCall(socket, *buf, len, flags) + EndIf + EndIf + + ProcedureReturn lResult +EndProcedure +; IDE Options = PureBasic 5.72 (Windows - x64) +; CursorPosition = 59 +; FirstLine = 18 +; Folding = --- +; EnableXP +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField4 = 1.0.0 \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/Module/PubServer.pb b/PureBasicNanoMsg/Example/Module/PubServer.pb new file mode 100644 index 0000000..5827d35 --- /dev/null +++ b/PureBasicNanoMsg/Example/Module/PubServer.pb @@ -0,0 +1,71 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../../Core/Enums.pbi" +IncludeFile "../../Core/NanomsgWrapper.pbi" + +UseModule NanomsgWrapper + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://*:1689" + +If DllOpen(lpszLibNnDll) + OpenConsole() + + Define Socket.i = NanomsgSocket::Socket(#AF_SP, #NN_PUB) + Define Rc.i = NanomsgSocket::Bind(Socket, lpszServerAddr) + + PrintN("Bind an IP address: " + lpszServerAddr) + + While 1 + Define *lpszBuffer = AllocateMemory(32) + Define lpszTopic.s = "quotes" + Define lpszMessage.s = lpszTopic + "#Bid:" + Random(9000, 1000) + ",Ask:" + Random(9000, 1000) + + NanomsgSocket::Recv(Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + Delay(10) + + Define lpszReturnMessage.s = PeekS(*lpszBuffer, -1, #PB_UTF8) + + If lpszReturnMessage <> "" + PrintN("Received: ") + PrintN(lpszReturnMessage) + EndIf + + NanomsgSocket::Send(Socket, lpszMessage, Len(lpszMessage), 0) + + FreeMemory(*lpszBuffer) + Wend + + NanomsgSocket::Close(Socket) + + CloseConsole() + + DllClose() +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 53 +; FirstLine = 2 +; Folding = - +; EnableXP +; Executable = ..\..\ModulePubServer.exe +; CurrentDirectory = ..\..\ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/Module/RepServer.pb b/PureBasicNanoMsg/Example/Module/RepServer.pb new file mode 100644 index 0000000..4daf2a4 --- /dev/null +++ b/PureBasicNanoMsg/Example/Module/RepServer.pb @@ -0,0 +1,70 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../../Core/Enums.pbi" +IncludeFile "../../Core/NanomsgWrapper.pbi" + +UseModule NanomsgWrapper + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://*:1700" + +If DllOpen(lpszLibNnDll) + OpenConsole() + + Define Socket.i = NanomsgSocket::Socket(#AF_SP, #NN_REP) + Define Rc.i = NanomsgSocket::Bind(Socket, lpszServerAddr) + + PrintN("Bind an IP address: " + lpszServerAddr) + + Define lTotal.l = 0 + + While 1 + lTotal = lTotal + 1 + + Define *lpszBuffer = AllocateMemory(32) + Define lpszMessage.s = "Hi " + lTotal + + NanomsgSocket::Recv(Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + Delay(10) + + PrintN("Received: ") + PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) + + NanomsgSocket::Send(Socket, lpszMessage, Len(lpszMessage), 0) + + FreeMemory(*lpszBuffer) + Wend + + NanomsgSocket::Close(Socket) + + CloseConsole() + + DllClose() +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 27 +; FirstLine = 1 +; Folding = - +; EnableXP +; Executable = ..\..\ModuleRepServer.exe +; CurrentDirectory = ..\..\ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/Module/ReqClient.pb b/PureBasicNanoMsg/Example/Module/ReqClient.pb new file mode 100644 index 0000000..0d153de --- /dev/null +++ b/PureBasicNanoMsg/Example/Module/ReqClient.pb @@ -0,0 +1,65 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../../Core/Enums.pbi" +IncludeFile "../../Core/NanomsgWrapper.pbi" + +UseModule NanomsgWrapper + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://localhost:1700" + +If DllOpen(lpszLibNnDll) + OpenConsole() + + Define Socket.i = NanomsgSocket::Socket(#AF_SP, #NN_REQ) + Define Rc.i = NanomsgSocket::Connect(Socket, lpszServerAddr) + + PrintN("Connect to Server: " + lpszServerAddr) + + Define i.i + + For i = 0 To 10 + Define *lpszBuffer = AllocateMemory(32) + Define lpszMessage.s = "From Client" + + NanomsgSocket::Send(Socket, lpszMessage, Len(lpszMessage), 0) + NanomsgSocket::Recv(Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + PrintN("Reply From Server: ") + PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) + + FreeMemory(*lpszBuffer) + Next + + NanomsgSocket::Close(Socket) + + Input() + CloseConsole() + + DllClose() +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 27 +; Folding = - +; EnableXP +; Executable = ..\..\ModuleReqClient.exe +; CurrentDirectory = ..\..\ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/Module/SubClient.pb b/PureBasicNanoMsg/Example/Module/SubClient.pb new file mode 100644 index 0000000..4aacee9 --- /dev/null +++ b/PureBasicNanoMsg/Example/Module/SubClient.pb @@ -0,0 +1,77 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../../Core/Enums.pbi" +IncludeFile "../../Core/NanomsgWrapper.pbi" + +UseModule NanomsgWrapper + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://localhost:1689" + +If DllOpen(lpszLibNnDll) + OpenConsole() + + Define Socket.i = NanomsgSocket::Socket(#AF_SP, #NN_SUB) + Define Rc.i = NanomsgSocket::Connect(Socket, lpszServerAddr) + + Define lpszSubscribe.s = "quotes" + + NanomsgSocket::Setsockopt(Socket, #NN_SUB, #NN_SUB_SUBSCRIBE, lpszSubscribe, Len(lpszSubscribe)) + +; Define i.i +; +; For i = 0 To 10 +; *lpszBuffer = AllocateMemory(32) +; +; NanomsgSocket::Recv(Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) +; +; PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) +; +; FreeMemory(*lpszBuffer) +; Next + + While 1 + Define *lpszBuffer = AllocateMemory(32) + + NanomsgSocket::Recv(Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) + + FreeMemory(*lpszBuffer) + + Delay(10) + Wend + + NanomsgSocket::Close(Socket) + + Input() + CloseConsole() + + DllClose() +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 47 +; FirstLine = 8 +; Folding = - +; EnableXP +; Executable = ..\..\ModuleSubClient.exe +; CurrentDirectory = ..\..\ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/Nanomsg.pb b/PureBasicNanoMsg/Example/Nanomsg.pb new file mode 100644 index 0000000..48b3e47 --- /dev/null +++ b/PureBasicNanoMsg/Example/Nanomsg.pb @@ -0,0 +1,60 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../Core/Nanomsg.pbi" + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global hLibrary.i = NnDllOpen(lpszLibNnDll) + +If hLibrary + OpenConsole() + + Define errorNo.i + + Define nnSymbolIndex.i + Define nnSymbolValue.l = 0 + Define nnSymbolName.s + + While nnSymbolIndex >= 0 + nnSymbolName = NnSymbol(hLibrary, nnSymbolIndex, @nnSymbolValue) + + If Len(nnSymbolName) = 0 + Break + EndIf + + PrintN("NanoMsg Symbol: " + nnSymbolName + " " + nnSymbolValue) + + errorNo = NnErrno(hLibrary) + + nnSymbolIndex = nnSymbolIndex + 1 + Wend + + Input() + CloseConsole() + + NnDllClose(hLibrary) +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 37 +; Folding = - +; EnableXP +; Executable = ..\Zmq.exe +; CurrentDirectory = ../ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/PubServer.pb b/PureBasicNanoMsg/Example/PubServer.pb new file mode 100644 index 0000000..74bb534 --- /dev/null +++ b/PureBasicNanoMsg/Example/PubServer.pb @@ -0,0 +1,70 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../Core/Nanomsg.pbi" + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://*:1689" + +Global hLibrary.i = NnDllOpen(lpszLibNnDll) + +If hLibrary + OpenConsole() + + Define Socket.i = NnSocket(hLibrary, #AF_SP, #NN_PUB) + Define Rc.i = NnBind(hLibrary, Socket, lpszServerAddr) + + PrintN("Bind an IP address: " + lpszServerAddr) + + While 1 + Define *lpszBuffer = AllocateMemory(32) + Define lpszTopic.s = "quotes" + Define lpszMessage.s = lpszTopic + "#Bid:" + Random(9000, 1000) + ",Ask:" + Random(9000, 1000) + + NnRecv(hLibrary, Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + Delay(10) + + Define lpszReturnMessage.s = PeekS(*lpszBuffer, -1, #PB_UTF8) + + If lpszReturnMessage <> "" + PrintN("Received: ") + PrintN(lpszReturnMessage) + EndIf + + NnSend(hLibrary, Socket, lpszMessage, Len(lpszMessage), 0) + + FreeMemory(*lpszBuffer) + Wend + + NnClose(hLibrary, Socket) + + CloseConsole() + + NnDllClose(hLibrary) +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 26 +; FirstLine = 1 +; Folding = - +; EnableXP +; Executable = ..\PubServer.exe +; CurrentDirectory = ../ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/RepServer.pb b/PureBasicNanoMsg/Example/RepServer.pb new file mode 100644 index 0000000..cea7eca --- /dev/null +++ b/PureBasicNanoMsg/Example/RepServer.pb @@ -0,0 +1,69 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../Core/Nanomsg.pbi" + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://*:1700" + +Global hLibrary.i = NnDllOpen(lpszLibNnDll) + +If hLibrary + OpenConsole() + + Define Socket.i = NnSocket(hLibrary, #AF_SP, #NN_REP) + + Define Rc.i = NnBind(hLibrary, Socket, lpszServerAddr) + + PrintN("Bind an IP address: " + lpszServerAddr) + + Define lTotal.l = 0 + + While 1 + lTotal = lTotal + 1 + + Define *lpszBuffer = AllocateMemory(32) + Define lpszMessage.s = "Hi " + lTotal + + NnRecv(hLibrary, Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + Delay(10) + + PrintN("Received: ") + PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) + + NnSend(hLibrary, Socket, lpszMessage, Len(lpszMessage), 0) + + FreeMemory(*lpszBuffer) + Wend + + NnClose(hLibrary, Socket) + + CloseConsole() + + NnDllClose(hLibrary) +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 26 +; Folding = - +; EnableXP +; Executable = ..\RepServer.exe +; CurrentDirectory = ..\ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/ReqClient.pb b/PureBasicNanoMsg/Example/ReqClient.pb new file mode 100644 index 0000000..0f0d350 --- /dev/null +++ b/PureBasicNanoMsg/Example/ReqClient.pb @@ -0,0 +1,64 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../Core/Nanomsg.pbi" + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://localhost:1700" + +Global hLibrary.i = NnDllOpen(lpszLibNnDll) + +If hLibrary + OpenConsole() + + Define Socket.i = NnSocket(hLibrary, #AF_SP, #NN_REQ) + Define Rc.i = NnConnect(hLibrary, Socket, lpszServerAddr) + + PrintN("Connect to Server: " + lpszServerAddr) + + Define i.i + + For i = 0 To 10 + Define *lpszBuffer = AllocateMemory(32) + Define lpszMessage.s = "From Client" + + NnSend(hLibrary, Socket, lpszMessage, Len(lpszMessage), 0) + NnRecv(hLibrary, Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + PrintN("Reply From Server: ") + PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) + + FreeMemory(*lpszBuffer) + Next + + NnClose(hLibrary, Socket) + + Input() + CloseConsole() + + NnDllClose(hLibrary) +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 26 +; Folding = - +; EnableXP +; Executable = ..\ReqClient.exe +; CurrentDirectory = ..\ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Example/SubClient.pb b/PureBasicNanoMsg/Example/SubClient.pb new file mode 100644 index 0000000..f235339 --- /dev/null +++ b/PureBasicNanoMsg/Example/SubClient.pb @@ -0,0 +1,76 @@ +;-------------------------------------------------------------------------------------------- +; Copyright (c) Ji-Feng Tsai. All rights reserved. +; Code released under the MIT license. +;-------------------------------------------------------------------------------------------- + +EnableExplicit + +IncludeFile "../Core/Nanomsg.pbi" + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://localhost:1689" + +Global hLibrary.i = NnDllOpen(lpszLibNnDll) + +If hLibrary + OpenConsole() + + Define Socket.i = NnSocket(hLibrary, #AF_SP, #NN_SUB) + Define Rc.i = NnConnect(hLibrary, Socket, lpszServerAddr) + + Define lpszSubscribe.s = "quotes" + + NnSetsockopt(hLibrary, Socket, #NN_SUB, #NN_SUB_SUBSCRIBE, lpszSubscribe, Len(lpszSubscribe)) + +; Define i.i +; +; For i = 0 To 10 +; Define *lpszBuffer = AllocateMemory(32) +; +; NnRecv(hLibrary, Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) +; +; PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) +; +; FreeMemory(*lpszBuffer) +; Next + + While 1 + Define *lpszBuffer = AllocateMemory(32) + + NnRecv(hLibrary, Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) + + FreeMemory(*lpszBuffer) + + Delay(10) + Wend + + NnClose(hLibrary, Socket) + + Input() + CloseConsole() + + NnDllClose(hLibrary) +EndIf +; IDE Options = PureBasic 6.12 LTS (Windows - x64) +; CursorPosition = 46 +; FirstLine = 4 +; Folding = - +; EnableXP +; Executable = ..\SubClient.exe +; CurrentDirectory = ../ +; IncludeVersionInfo +; VersionField2 = Inwazy Technology +; VersionField3 = PureBasicZMQ +; VersionField9 = Ji-Feng Tsai +; VersionField13 = jiowcl@gmail.com \ No newline at end of file diff --git a/PureBasicNanoMsg/Library/x64/nanomsg.dll b/PureBasicNanoMsg/Library/x64/nanomsg.dll new file mode 100644 index 0000000..12937c3 Binary files /dev/null and b/PureBasicNanoMsg/Library/x64/nanomsg.dll differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2bfda3 --- /dev/null +++ b/README.md @@ -0,0 +1,160 @@ +# PureBasicNanoMsg + +Nanomsg Wrapper for PureBasic Programming Language. + +![GitHub](https://img.shields.io/github/license/jiowcl/PureBasicNanoMsg.svg) +![PureBasic](https://img.shields.io/badge/language-PureBasic-blue.svg) + +## Environment + +- Windows 7 above (recommend) +- PureBasic 6.0 above (recommend) +- [Nanomsg](https://github.com/nanomsg) + +## How to Build + +Building requires PureBasic Compiler and test under Windows 10. +Module features require PureBasic 5.20 and above. + +## Example + +Publisher Server + +```purebasic +EnableExplicit + +IncludeFile "../../Core/Enums.pbi" +IncludeFile "../../Core/NanomsgWrapper.pbi" + +UseModule NanomsgWrapper + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://*:1689" + +If DllOpen(lpszLibNnDll) + OpenConsole() + + Define Socket.i = NanomsgSocket::Socket(#AF_SP, #NN_PUB) + Define Rc.i = NanomsgSocket::Bind(Socket, lpszServerAddr) + + PrintN("Bind an IP address: " + lpszServerAddr) + + While 1 + Define *lpszBuffer = AllocateMemory(32) + Define lpszTopic.s = "quotes" + Define lpszMessage.s = lpszTopic + "#Bid:" + Random(9000, 1000) + ",Ask:" + Random(9000, 1000) + + NanomsgSocket::Recv(Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + Delay(10) + + Define lpszReturnMessage.s = PeekS(*lpszBuffer, -1, #PB_UTF8) + + If lpszReturnMessage <> "" + PrintN("Received: ") + PrintN(lpszReturnMessage) + EndIf + + NanomsgSocket::Send(Socket, lpszMessage, Len(lpszMessage), 0) + + FreeMemory(*lpszBuffer) + Wend + + NanomsgSocket::Close(Socket) + + CloseConsole() + + DllClose() +EndIf +``` + +Subscribe Client + +```purebasic +EnableExplicit + +IncludeFile "../../Core/Enums.pbi" +IncludeFile "../../Core/NanomsgWrapper.pbi" + +UseModule NanomsgWrapper + +Global lpszCurrentDir.s = GetCurrentDirectory() + +; Nanomsg version (x64) +CompilerIf #PB_Compiler_Processor = #PB_Processor_x64 + Global lpszLibNnDir.s = "Library/x64" + Global lpszLibNnDll.s = lpszCurrentDir + lpszLibNnDir + "/nanomsg.dll" + + SetCurrentDirectory(lpszCurrentDir + lpszLibNnDir) +CompilerEndIf + +Global lpszServerAddr.s = "tcp://localhost:1689" + +If DllOpen(lpszLibNnDll) + OpenConsole() + + Define Socket.i = NanomsgSocket::Socket(#AF_SP, #NN_SUB) + Define Rc.i = NanomsgSocket::Connect(Socket, lpszServerAddr) + + Define lpszSubscribe.s = "quotes" + + NanomsgSocket::Setsockopt(Socket, #NN_SUB, #NN_SUB_SUBSCRIBE, lpszSubscribe, Len(lpszSubscribe)) + +; Define i.i +; +; For i = 0 To 10 +; *lpszBuffer = AllocateMemory(32) +; +; NanomsgSocket::Recv(Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) +; +; PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) +; +; FreeMemory(*lpszBuffer) +; Next + + While 1 + Define *lpszBuffer = AllocateMemory(32) + + NanomsgSocket::Recv(Socket, *lpszBuffer, MemorySize(*lpszBuffer), 0) + + PrintN( PeekS(*lpszBuffer, -1, #PB_UTF8) ) + + FreeMemory(*lpszBuffer) + + Delay(10) + Wend + + NanomsgSocket::Close(Socket) + + Input() + CloseConsole() + + DllClose() +EndIf +``` + +## License + +Copyright (c) 2017-2024 Ji-Feng Tsai. +Code released under the MIT license. + +## TODO + +- More examples + +## Donation + +If this application help you reduce time to coding, you can give me a cup of coffee :) + +[![paypal](https://www.paypalobjects.com/en_US/TW/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3RNMD6Q3B495N&source=url) + +[Paypal Me](https://paypal.me/jiowcl?locale.x=zh_TW)