Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua Sockets Erroring Out on Windows #1174

Closed
Netbrian opened this issue Apr 7, 2018 · 16 comments

Comments

Projects
None yet
5 participants
@Netbrian
Copy link

commented Apr 7, 2018

When trying to use the TestCommunication_All.lua (with the Python server running in the background), I get the following errors when it runs the socket commands comm.socketServerScreenShot() and comm.socketServerScreenShotResponse() (the HTTP and memory mapped file commands worked as expected). This happens with both LUA engines, and on both the current stable build and the latest dev build (a5eca36). I'm using the latest version of Windows 10 for my testing.

NLua.Exceptions.LuaScriptException: KopiLua.LuaNativeFunction

NLua.Exceptions.LuaException: unprotected error in call to Lua API (0)
at NLua.Lua.PanicCallback(IntPtr luaState)
at lua_error(lua_State* )
at NLua.ObjectTranslator.throwError(IntPtr luaState, Object e)
at NLua.Lua.SetPendingException(Exception e)
at NLua.LuaMethodWrapper.call(IntPtr luaState)
at NLua.MetaFunctions.runFunctionDelegate(IntPtr luaState)
at lua_resume(lua_State* , Int32 )
at BizHawk.Client.EmuHawk.EmuLuaLibrary.ResumeScript(Lua script)
at BizHawk.Client.EmuHawk.LuaConsole.<>c__DisplayClass55_0.b__1()
at BizHawk.Client.Common.LuaSandbox.Sandbox(Action callback, Action exceptionCallback)

@vadosnaprimer

This comment has been minimized.

Copy link
Contributor

commented May 10, 2018

@Ashafix halp

@YoshiRulz YoshiRulz added the Topic-Lua label Jan 29, 2019

@ajbradberry96

This comment has been minimized.

Copy link

commented Feb 7, 2019

I'm getting an identical error using LuaSocket after the script has been running for around an hour or so.

@Ashafix

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2019

@Netbrian, @vadosnaprimer : apologies, the email totally totally slipped my attention.
My guess is that either the IP or the port was wrong.
I updated the PyEmuhawk file on Github. Now you can find the command line parameters needed for Emuhawk in the output.
https://github.com/Ashafix/PyEmuHawk

The lua test file was also updated.
TestCommunication_All.txt

I'll try to carve out some time to work on better error messages.

@ajbradberry96 : I also encountered random disconnects but I couldn't figure out why it happened, sometimes the socket connection was stable for hours and sometimes it stopped after an hour. At the end I'm using the HTTP connection because it was easier to use and the delay was minimal compared to the time needed for the calculations.

@Netbrian

This comment has been minimized.

Copy link
Author

commented May 12, 2019

@Netbrian, @vadosnaprimer : apologies, the email totally totally slipped my attention.
My guess is that either the IP or the port was wrong.
I updated the PyEmuhawk file on Github. Now you can find the command line parameters needed for Emuhawk in the output.
https://github.com/Ashafix/PyEmuHawk

The lua test file was also updated.
TestCommunication_All.txt

I'm sorry for taking so long to reply.

When I ran it with the latest dev version, I got the following error message:

NLua.Exceptions.LuaScriptException: KopiLua.LuaNativeFunction

The Python server didn't show any sign of communications.

@Ashafix

This comment has been minimized.

Copy link
Contributor

commented May 12, 2019

@Netbrian : Can you add more details? Which OS, Python version, etc.? Also please post the output of the Python script. Thanks!

@Netbrian

This comment has been minimized.

Copy link
Author

commented May 12, 2019

@Netbrian : Can you add more details? Which OS, Python version, etc.? Also please post the output of the Python script. Thanks!

Sure!

I'm running updated Windows 10.
Bizhawk is the latest dev version, be0f5f8 or something.
Python is version 3.6.
LUA output when I run the test communications all script (unmodified) is --

Baseline: 1.659 secs
NLua.Exceptions.LuaScriptException: KopiLua.LuaNativeFunction

Python Output is

Starting HTTP server
Running HTTP server at: 0.0.0.0:9876
HTTP server address is 0.0.0.0, probably you can use localhost or 192.168.0.107 as its IP address
Starting socket server
Socket server running at 192.168.0.107:9990

Settings for Emuhawk:
--socket_ip=192.168.0.107 --socket_port=9990 --url_get=http://192.168.0.107:9876/get --url_post=http://192.168.0.107:9876/post

establishing connection
waiting for connection

It eventually gives up and disconnects.

Do you need any further information from my end?

@Ashafix

This comment has been minimized.

Copy link
Contributor

commented May 12, 2019

Thanks for the info!

Can you check two more things
a) open a browser, go to http://192.168.0.107:9876/get and check if it says "hi!"
b) after starting PyEmuhawk.py, open another Python console and try the following script

import socket
s = socket.create_connection(('192.168.0.107', 9990))
s.send(b'hello\r\n')

PyEmuhawk should print SOCKET received and above some details about the incoming connection.

I just want to make sure that the problem is actually with the Emuhawk part and not with the Python server.

If both tests from above work, please restart PyEmuhawk and then open Emuhawk from the command line via Emuhawk.exe --socket_ip=192.168.0.107 --socket_port=9990. (or whatever the output from PyEmuhawk says).

Then go to Tools --> Lua Console and run the following commands:

comm.socketServerGetInfo()
comm.socketServerScreenShot()

The first command should give you the IP and port again.
The second command should return Screenshot was sent in the Lua log and a SOCKET received message in the PyEmuhawk window.

@Netbrian

This comment has been minimized.

Copy link
Author

commented May 12, 2019

OK!

PyEmuHawk --

a. The message displayed correctly.
b. Socket received was printed.

Bizhawk:

I ran it as suggested.

comm.socketServerGetInfo() returned "NLua.Exceptions.LuaScriptException: [string "chunk"]:1: attempt to call field 'socketServerGetInfo' (a nil value)"

comm.socketServerScreenShot() seems to have worked fine. PyEmuHawk acknowledged receiving something.

@Ashafix

This comment has been minimized.

Copy link
Contributor

commented May 19, 2019

Thanks!

I think I found the problem. socketServerScreenShot checks whether the connection is already established and creates a new connection if none exists. socketServerSend does not. Therefore calling socketServerScreenShot before socketServerSend works but only socketServerSend does not.

The code was changed accordingly. Can you try the commit in my fork? Ashafix@5b981da

If this doesn't work either on your system or you need the compiled exe file, feel free to email me.

@Netbrian

This comment has been minimized.

Copy link
Author

commented May 19, 2019

Oh great!

I e-mailed you regarding the Windows binaries too. Thank you!

@Netbrian

This comment has been minimized.

Copy link
Author

commented May 19, 2019

OK, looks like we've made progress. It looks like it's expecting a parameter for a memory mapped file, but it doesn't look like PyHawk is set up to feed one in.

On the LUA end --

Baseline: 1.657 secs
Socket server: -0.015 secs
Memory mapped file was not initialized, please initialize it via the command line
NLua.Exceptions.LuaScriptException: KopiLua.LuaNativeFunction

On the Python End --

"C:\Users\Brian Trautman\PycharmProjects\Emuhawk\venv\Scripts\python.exe" "C:/Users/Brian Trautman/PycharmProjects/Emuhawk/hawk.py"
Starting HTTP server
Running HTTP server at: 0.0.0.0:9876
HTTP server address is 0.0.0.0, probably you can use localhost or 192.168.0.107 as its IP address
Starting socket server
Socket server running at 192.168.0.107:9990

Settings for Emuhawk:
--socket_ip=192.168.0.107 --socket_port=9990 --url_get=http://192.168.0.107:9876/get --url_post=http://192.168.0.107:9876/post

establishing connection
waiting for connection
<socket.socket fd=940, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('192.168.0.107', 9990), raddr=('192.168.0.107', 51715)>, ('192.168.0.107', 51715)connection finished
SOCKET received

@Ashafix

This comment has been minimized.

Copy link
Contributor

commented May 19, 2019

Can you add --mmf=temp.mmf to your Emuhawk command line call? This command should get rid of the memory mapped error.
http://tasvideos.org/Bizhawk/CommandLine.html

@Netbrian

This comment has been minimized.

Copy link
Author

commented May 19, 2019

Looks like we're good now!

I actually checked that page beforehand, but I don't see where it documents arguments like mmf or socket_ip. Is there a different site for the dev version to check?

Baseline: 1.657 secs
Socket server: -0.022 secs
Memory mapped files: -0.001 secs
Testing HTTP server
HTTP get: -0.007 secs
HTTP post: 0.001 secs
#####################
Testing HTTP server response
HTTP GET looks fine: No errors occurred
HTTP POST looks fine: No errors occurred
Trying to find minimal timeout for Socket server
Best timeout: 1 msecs
Best time: 0.003 secs

@vadosnaprimer

This comment has been minimized.

Copy link
Contributor

commented Jun 8, 2019

WHat's the current status of this?

@Netbrian

This comment has been minimized.

Copy link
Author

commented Jun 9, 2019

I tested and verified it worked on the extra build posted. I don't know if that's been committed to the main Bizhawk or not -- when that happens, I can retest, and close this out.

You might also want to update the documentation on the commandline options -- it doesn't seem to include information on the socket stuff.

YoshiRulz added a commit that referenced this issue Jun 9, 2019

@YoshiRulz

This comment has been minimized.

Copy link
Member

commented Jun 9, 2019

opened #1583 (link to build)

@YoshiRulz YoshiRulz closed this in 0d61030 Jun 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.