Socket Communication Error

Asked by toshikazu tsuzuki on 2017-01-10

1.1.994(2015-10-22_11:34nightly)/Windows6.1/Java7(32)1.7.0_79-b15

I have a problem of socket communications with sikuli.
Could you please help me?

I wrote the following ruby script as server.

--< ShareData.rb >----------------------------------------------
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-

require 'socket'

# server settings
host_name = "127.0.0.1"
host_port = 5001

serv = TCPServer.open(host_name, host_port)

#-------- request from a client
km_data = {} # shared data
begin
 loop do
  Thread.start(serv.accept) do |sock|
   puts "client accept"
   while msg = sock.gets.chomp
    data = msg.split(',', -1)
    req_type = data[0]

    case req_type
    #-------- set: setter of data, format: "set", key, data
    when "set"
     km_data[ data[1] ] = data[2]
     puts km_data
    #-------- get: getter of data, format: "get", key
    when "get"
     #-------- send the data
     if km_data.has_key?(data[1])
      sock.puts(km_data[ data[1] ],"\r\n")
     else
      sock.puts("\r\n")
     end
    else
     puts "req_type = #{req_type}"
    end
   end
   sock.close
  end
 end
rescue
 puts "ERR:TCPServer close."
 sleep(10)
end

serv.close

----------------------------------------------------------------

And I wrote the following sikuli scripts as client.

--< sample.py >-------------------------------------------------
# -*- coding: utf-8
import socket
from contextlib import closing

host = "127.0.0.1" # host name
port = 5001 # port number
bufsize = 4096 # buffer size

def shareDataSet(key, data):
    print("shareDataSet(): key=%s data=%s" % (key, data))

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((host, port))

    req = "set" + "," + key + "," + str(data)
    sock.send(req)
    print(">>>SET : %s" % (data))
    sock.close()

key = "key-sample"

# set data
data_set = "5678"
shareDataSet(key, data_set)

----------------------------------------------------------------

I executed them in the following steps:

1. Run the server with the command.
    % ruby ShareData.rb
2. Startup the client(sikuli) with the runsikulix.cmd.
3. Run the sample.py on the sikuli.
    ---- This works correctly.
4. Run the sample.py on the sikuli again, without quitting the sikuli.
    ---- Java outputs an exception.

The exception is happened at the line 359 of sikulix.jar\Lib\_socket.py,
And this is not happened at the version 1.0.1 of the sikuli.

If you have an advice or a prevention, and give it to me,
it will be my great help.

Thanks.

Question information

Language:
English Edit question
Status:
Expired
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-01-10
Last reply:
2017-01-25
RaiMan (raimund-hocke) said : #1

SikuliX 1.0.1 uses Jython 2.5 and SikuliX 1.1.1+ use Jython 2.7.

Your problem is a Jython problem, that happens if the same script is run again in the same interpreter instance. The socket implementation does not seem to be stateless.

Solution: run the the script from commandline (even in parallel to having the script open in The IDE).

toshikazu tsuzuki (toshikazu) said : #2

Thank you for your answer.
It is very helpful.

But I still want to use SikuliIDE.

And according to your answer,
it seems to be no problem to use Jython 2.5, instead of 2.7.

Does it really cause no problem?

If so, it seems OK to install the Sikuli 1.1.0 with Jython 2.5,
which is renamed to "jython-standalone-2.7.0.jar"
and placed under the "Downloads" folder.

I want to hear your opinion.

I appreciate to your answer.

Thanks.

Launchpad Janitor (janitor) said : #3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

toshikazu tsuzuki (toshikazu) said : #4

I'm sorry.

I'll try to solve the problem with an external socket communication program.

Thank you.