FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Escuchar comunicaciones por puerto IP.
Posts: 139
Joined: Sun Apr 23, 2006 09:00 AM
Escuchar comunicaciones por puerto IP.
Posted: Thu Apr 10, 2014 10:22 AM

Hola a todos.

Tengo una pesadora que se comunica con un programa a trav茅s de una IP.
Es un programa de terceros y quiero sustituirlo por uno de desarrollo propio.
S茅 como establecer comunicaci贸n a trav茅s del puerto serie pero en este caso me interesar铆a saber c贸mo puedo capturar la informaci贸n que env铆a. Si fuera posible mediante programaci贸n, y si no, con alg煤n software que dicho tr谩fico me lo enviara o un fichero de texto que peri贸dicamente mi programa leer铆a.
Gracias por adelantado.

Un saludo,

Fernando

Las Palmas de Gran Canaria
Posts: 883
Joined: Tue Oct 11, 2005 11:57 AM
Re: Escuchar comunicaciones por puerto IP.
Posted: Thu Apr 10, 2014 02:04 PM

Fernando..
Puedes enviar la marca y modelo de la pesa.

Yo tengo algunas con un cliente, pero la comunicacion IP es solo para programarlas y enviarles detalle de precios, codigos y productos, y la puerta serial para enviar en vivo el pesaje.

A ver si te puedo ayudar.

Desde Chile
Adolfo

;-) Ji,ji,ji... buena la cosa... "all you need is code"

http://www.xdata.cl - Desarrollo Inteligente
----------
Asus TUF F15, 32GB Ram, 2 * 1 TB NVME M.2, GTX 1650
Posts: 654
Joined: Mon May 29, 2006 03:14 PM
Re: Escuchar comunicaciones por puerto IP.
Posted: Mon Apr 14, 2014 09:36 PM
Mira a ver si te vale este c贸digo:
Code (fw): Select all Collapse
public cIPhost:="192.168.1.170 聽",nPuerto:=10001,pSocket:=0,cTrama:="",cResponse:="",;
聽 聽 聽 聽nBytes:=0,cBuffer:=""
INetInit()
pSocket:=INetConnectIP(cIPhost,nPuerto)
if INetErrorCode(pSocket)<>0
聽 聽MsgAlert("Socket error:"+;
聽 聽 聽 聽 聽 聽 INetErrorDesc(pSocket)+;
聽 聽 聽 聽 聽 聽 " ("+alltrim(str(INetErrorCode(pSocket)))+")","隆 AVISO !")
聽 聽INetCleanUp()
聽 聽quit
endif
INetSetTimeout(pSocket,5000)
cTrama:=""
cResponse:=""
nSegundos:=seconds()
do while .T. // De este bucle hay que controlar cuando se quiere salir y como.
聽 聽nBytes :=1500
聽 聽cBuffer:=space(nBytes)
聽 聽nBytes :=INetDGramRecv(pSocket,@cBuffer,nBytes)
聽 聽cBuffer:=left(cBuffer,nBytes)
聽 聽cTrama:=cTrama+cBuffer // En la variable "cTrama" se acumula los contenidos de las tramas recibidas...
聽 聽.../...
enddo
INetClose(pSocket)
INetCleanUp()


Tienes que linkar la librer铆a \xHarbour\lib\tip.lib

Y las funciones usadas son:
INetInit() : Initializes the sockets subsystem.
Syntax
INetInit() --> NIL
Arguments
no arguments available
Return value
The return value is always NIL.
Description
Function inetInit() must be called to initialize the sockets subsystem and allocate all required memory resources. It is recommended to place one call to inetInit() at the begin of a program that uses sockets. After the sockets subsystem is initialized, function inetConnect() or inetAccept() can be called to establish a sockets connection.
Note:
call function inetCleanup() to release memory resources for the sockets subsystem, when sockets are no longer needed.


INetConnectIP() : Establishes a sockets connection to a server using the IP address.
Syntax
INetConnectIP( <cIPAddress>, <nPort> ) --> pSocket
or
INetConnectIP( <cIPAddress>, <nPort>, <pSocket> ) --> NIL
Arguments
<cIPAddress>
This is a character string holding IP address of the server in dotted notation (e.g. "192.168.1.145").
<nPort>
This is the numeric port number on the local computer to use for the socket connection. The default internet port is 80.
<pSocket>
Optionally, a socket created with inetCreate() or previously closed with inetClose() can be passed to establish a connection.
Return value
If called with two parameters, the return value is a pointer to a socket. If a socket is passed as third parameter, the return value is NIL.
Description
inetConnectIP() does the same as inetConnect() except for not resolving the IP address from the server's URL, or DNS name. inetConnectIP() accepts only the IP address of the server in dottet notation. Therefore, the function is thread safe and can be called simultaneously in multiple threads.
If the connection is successfully established, the socket can be used for sending and receiving data to/from the server. If the connection fails, the cause of failure can be detected with inetErrorCode() .


INetErrorCode() : Returns the last sockets error code.
Syntax
INetErrorCode( <pSocket> ) --> nErrorCode
Arguments
<pSocket>
This is a pointer to a socket.
Return value
The function returnes the error code of the last sockets operation as a numeric value.
Description
When a sockets function fails, the error code of the sockets operation is stored in <pSocket> and can be retrieved later with function inetErrorCode(). This error code remains with <pSocket> until a new sockets function is called with this socket or inetClearError() is executed.
To obtain a human readable description of a sockets error, call inetErrorDesc() with <pSocket>.


INetErrorDesc() : Returns a descriptive error message
Syntax
INetErrorDesc( <pSocket> ) --> cErrorMessage
Arguments
<pSocket>
This is a pointer to a socket.
Return value
The function retunrs a character string holding an error message. If no error occurred, the return value is a null string ("").
Description
Function inetErrorDesc() is used to obtain the description of an error when a socket function fails. It translates the numeric error code into a human readable message.


INetCleanup() : Releases memory resources for sockets.
Syntax
INetCleanup() --> NIL
Arguments
no arguments available
Return value
The return value is always NIL.
Description
inetCleanup() should be called at the end of any program using sockets functions, or when sockets are no longer required. The function releases all memory resources allocated with inetInit() .


INetSetTimeout() : Sets a timout value in milliseconds for a socket.
Syntax
INetSetTimeout( <pSocket>, <nMilliSeconds> ) --> NIL
Arguments
<pSocket>
This is a pointer to a socket created from any socket creation function.
<nMilliSeconds>
A numeric value specifies the timeout period in milliseconds.
Return value
The return value is always NIL.
Description
inetSetTimeout() sets the timeout value for a socket, after which a blocking sockets function returns. If the blocking sockets function is not completed withing the timeout period, it returns, and a sockets error of -1 is set.
Refer to function inetSetPeriodCallback() for an example of taking advantage of a timeout value.
Note:
high-level sockets functions, like inetRecvAll() , internally call their low-level counterpart inetRecv() multiple times until all data is retrieved. The timeout value is applied to all individual inetRecv() calls, not for the entire inetRecvAll() call.


INetDGramRecv() : Reads data from a datagram socket.
Syntax
INetDGramRecv( <pSocket>, ;
@<cBuffer>, ;
[<nBytes>] ) --> nReceivedBytes
Arguments
<pSocket>
This is a pointer to a socket as returned by inetDGram() or inetDGramBind()
<cBuffer>
A memory variable holding a character string must be passed by reference to inetDGramRecv(). It must have at least <nBytes> characters.
<nBytes>
This is a numeric value specifying the number of bytes to transfer from the socket into the memory variable <cBuffer>. It defaults to Len(<cBuffer>).
Return value
The function returns a numeric value indicating the number of bytes read from the socket. If the return value is smaller than Len(<cBuffer>), either no more bytes are available, or a network error ocurred. This can be identified using function !LINK INetErrorCode() !ELINK.
Description
inetDGramRecv() blocks the current thread until <nBytes> bytes are read from a datagram socket <pSocket>. The received bytes are copied into the memory variable <cBuffer>, which must be passed by reference.
To avoid blocking, function inetDataReady() can be used to detect if incoming data is available, or a timeout value can be set with inetSetTimeout() .
Note:
it is not guaranteed that all the data required to be read is sent from the kernel to the application. The kernel just returns the last complete datagram that has been received, up to <nBytes> bytes.
Refer to function inetDGramSend() for an example of datagram exchange between two processes.


INetClose() : Closes a connection on a socket.
Syntax
INetClose( <pSocket> ) --> nError
Arguments
<pSocket>
This is a pointer to a socket.
Return value
The function returns zero on success, or -1 on failure.
Description
inetClose() closes a socket and notifies both ends of the connection. If threads are executing a blocking sockets function with <pSocket>, they will terminate their wait state and a socket error is set ("socket closed"). This causes all threads waiting on a blocking sockets function to resume so they can report a sockets error.
If the return value is not zero, use function inetErrorCode() to obtain information about failure.
Mi abuelo dec铆a: Los aviones vuelan porque Dios quiere, y los helic贸pteros ni Dios sabe porque vuelan.

FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013

Continue the discussion