Socket Communication Error

Asked by toshikazu tsuzuki on 2017-01-10


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 = ""
host_port = 5001

serv =, host_port)

#-------- request from a client
km_data = {} # shared data
 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")
     puts "req_type = #{req_type}"
 puts "ERR:TCPServer close."



And I wrote the following sikuli scripts as client.

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

host = "" # 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)
    print(">>>SET : %s" % (data))

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 on the sikuli.
    ---- This works correctly.
4. Run the on the sikuli again, without quitting the sikuli.
    ---- Java outputs an exception.

The exception is happened at the line 359 of sikulix.jar\Lib\,
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.


Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
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.


Can you help with this problem?

Provide an answer of your own, or ask toshikazu tsuzuki for more information if necessary.

To post a message you must log in.