|
Post by Chris Iverson on Feb 5, 2020 14:31:33 GMT -5
Now I know why the original LB prototypes were defined as double: it's typed as double because the function in C is written as accepting a double, and it converts it down to an unsigned int in code.
gmexport const char* buffer_read_string(double id) { Buffer *b = gmdata.FindBuffer(gm_cast<unsigned int>(id)); if(b == NULL) return ""; gmreturnstring = b->ReadString(); return gmreturnstring.c_str(); }
gmexport double buffer_write_string(double id, const char* string) { Buffer *b = gmdata.FindBuffer(gm_cast<unsigned int>(id)); if(b == NULL) return 0; b->WriteString(string); return 1; }
That's a problem, because LB's ulong is 4 bytes, whereas a double is 8 bytes.
This is some of the messiest C code I've ever seen, and I don't know why literally everything is defined as double. I suspect this was written by someone that didn't know proper datatype management, and made everything doubles because "there, it fits".
The underlying access code doesn't use doubles, so I don't know why the metaobject they use for this uses doubles for literally everything.
|
|
|
Post by Rod on Feb 5, 2020 14:40:50 GMT -5
Ok, until Ntech provides us with more info and a step by step guide about how the .dll should be use we should just leave it alone.
UDP activity is bound to surface again so some simple socket and udpsocket code would be a very worthwhile addition to the forum.
|
|
|
Post by Chris Iverson on Feb 5, 2020 14:49:55 GMT -5
UDP is an addition I was planning to make to the DLL I had, I think I'll restart progress on that soon.
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Feb 5, 2020 14:52:43 GMT -5
Well the OP has been active on the forum but hasn't responded to the post so assume it's actually just a repost of someone else's code. I've found the http DLL 2 orginal. linkDocumentation is better at least. EDIT: Also Chris I understood the first part but then nothing! I need UDP for this project, it the only method that the connected equipment uses.
|
|
|
Post by Chris Iverson on Feb 5, 2020 16:16:42 GMT -5
In that case, I think I have an alternative for you - mesock32, an old DLL we used for basic TCP connections, I found out is able to use UDP, as well. I was able to get UDP working through some trial and error. The DLL you can get from the Alyce's Restaurant website: alycesrestaurant.com/lbpe/files/mesock32.dllAnd here's some basic code that connects to a UDP server on port 50000, sends a message, and prints the response that comes back. Call NetInit print "NetSetUDP - ";NetSetUDP()
hSock = NetOpen("localhost", 50000) print "hSock - ";hSock
a = NetSend(hSock, "myDataKDFSLKE") print "NetSend - ";a
print NetReceive$(hSock)
a = NetClose(hSock) print "NetClose - ";a call NetTerm
Sub NetInit open "mesock32" for DLL as #me End Sub
Sub NetTerm close #me End Sub
Function NetSetUDP() NetSetUDP = NetSetOption(1) End Function
Function NetSetTCP() NetSetTCP = NetSetOption(0) End Function
Function NetSetOption(opt) Calldll #me, "TCP_SetOption",_ opt as long,_ NetSetOption as long End Function
''''Function TCPOpen()'''''''''' Function NetOpen(address$,Port) Timeout=1000 calldll #me, "Open", address$ As ptr,_ Port As Long,_ Timeout As Long, re As Long NetOpen=re End Function
''''Function TCPReceive$()'''''''''' Function NetReceive$(handle) buffer=4096 all=0 calldll #me, "ReceiveA" ,handle As Long,_ buffer As Long,_ all As Long, re As long if re<>0 then NetReceive$ = winstring(re) End Function
''''Function TCPPrint()'''''''''' Function NetSend(handle,text$) calldll #me, "SendA", handle As Long,_ text$ As ptr,re As Long NetSend=re End Function
''''Function TCPClose()'''''''''' Function NetClose(handle) calldll #me, "CloseA",handle As Long,_ NetClose As Long End Function
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Feb 5, 2020 16:31:43 GMT -5
Yes I've used mesock32 before, I didn't realise you could use this for UDP. I shall give this a try.
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Feb 6, 2020 13:11:05 GMT -5
IS there a GLOBAL statement missing from this code?
|
|
|
Post by Chris Iverson on Feb 6, 2020 13:16:01 GMT -5
No, and I just tested it again to be sure, and it runs successfully.
Is it not running for you?
|
|
|
Post by Rod on Feb 7, 2020 5:09:11 GMT -5
I am pretty new to UDP indeed anything that involves networking. I installed UDP Sender/Receiver from the app store. It lets me open a port fairly easily.
This is the log which shows that it is listening on local port 50000 Listening on Port 50000 Disconnected cleared
This is the results of running the program NetSetUDP - -1 hSock - -3 NetSend - -1 Error Number: 24 Error Description: Device timeout NetClose - -1
I don't seem to get a connection but perhaps there is something else I need to do?
|
|
|
Post by Chris Iverson on Feb 7, 2020 12:04:42 GMT -5
Does the UDP Sender/Receiver app show that it received anything? The code, as written, is sending data, and expecting a response back. It's showing a successful connection, and a successful send. That UDP Sender/Receiver app might not be sending anything back. EDIT: I tried the app from the store, and I couldn't get it to work. I wonder if it's an issue with the app. I myself used a python script to test it. Python 3.7 is available via the MS store(and you can get a shortcut there by typing "python" into your console on windows 10). Once python is installed, you can use the pip command to install the udp-test module. pip install udp-test Then, you can run it with the following command: python -m udp_test server -p 50000 This will set up an echo server running on port 50000. Anything you send to that port will get set back to the sender. I'm going to try another method of testing UDP, as well. EDIT: I was able to get it to work with the Packet Sender app, at packetsender.com/, as well.
|
|
|
Post by colinmcm on Feb 7, 2020 13:49:33 GMT -5
Hi Chris, I too tried your code with the Windows app, and got similar results to Rod. The Python script recieves the message from LB, but LB does not recieve a reply, as far as I can tell. It just sits there and waits. The python script prints the following message on the console "got a message from 127.0.0.1 : 52676 ==> myDataKDFSLKE" .
I do not know where that port number came from, obviously it is not in the LB program.
Colin McMurchie
|
|
|
Post by pandawdy on Feb 7, 2020 13:59:25 GMT -5
Wireshark is pretty useful for looking at data going in and out.
|
|
|
Post by pandawdy on Feb 7, 2020 13:59:57 GMT -5
I have some code that does work for sending UDP out.. but I have not figured out how to receive it back.
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Feb 7, 2020 14:32:45 GMT -5
I cannot get the code (posted by Chris) to work..... I get a Error 57 - Device I/O error. This is the TX side of things. If I comment out the TX call, only using the RX side I get Error 24 - Device timeout. I used TCPView (M$ SysInternals) link, despite the name it shows both TCP/UDP connections, when you run the code, it doesn't show it actually open the port. I then use wireshark to "watch" the packets. This, obviously shows nothing, as the port didn't open.
|
|
|
Post by Rod on Feb 7, 2020 14:39:49 GMT -5
The Windows UDP send/receive app gets nothing. I can set up two ports using my local IP address and send and receive data with the app but I am not sure what that proves. I will try the python module and report back.
edit, failed at the first or second hurdle. Python 3.7.6 installed but I get an error
>>> pip install udp-test SyntaxError: invalid syntax >>>
|
|