Open whenst opened 8 years ago
Update: The problem was that the port was already in use. If I changed the port it works. So, here's my question: How do I close the port if I exit my Matlab script prematurely? (i.e., before I can run close_connection in my script)
Thanks
Update #2: I tried changing the socket option to allow it to use a socket before the default wait time had expired. I added sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) to the EyeTribe_Matlab_server.py script. But this did not work, although it should. I was still getting "Address already in use" error. As a work around I added the following...
while True:
try:
sock.bind((MLIP,MLPORT))
except socket.error as exc:
if exc.args[0] != 48:
raise
print 'Port', MLPORT, 'already in use'
MLPORT += 1
print 'Trying port', MLPORT
else:
break
Then I edited the eye tribe_init script to accept this port number as an input (manually). I.e.,
MyMatlabScript(portnumber) [success,connection] = eye tribe_init('test', portnum);
This isn't ideal, but I wasn't able to figure out how, using the system function in Matlab, I could retrieve the port number from the python script. Any ideas about this would be very helpful!
Thanks
Update # 3: My new idea, again not ideal, is to have the python script generate a txt file with the port number that works, which is then read by eyetribe_init.m. This way at least you don't have to manually enter the port number into eyetribe_init.
Ideally, I could get sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) to work. But so far I've had no luck. I've not investigated why, I'm not experienced in python, so hopefully someone who is will be able to help!
Thanks
Thanks for flagging this up, and for your work in narrowing down the issue! Will have a look at your initial solution, which I think is the most elegant. Hope we can find out why it doesn't work as expected.
Hello,
I'm running Matlab 2015b, on OS X 10.11. eyetribe_init gets stuck at this point and I'm not sure why...
Operation terminated by user during instrument/get (line 77) In instrument/subsref (line 117) result = get(indexObj, prop1); In eyetribe_send_command (line 22) if connection.BytesAvailable > 0 In eyetribe_init (line 23) message = eyetribe_send_command(connection, 'Hi, this is Matlab!');
Any ideas?
Thanks