Giter VIP home page Giter VIP logo

Comments (6)

fahhem avatar fahhem commented on May 20, 2024

Hmm, TcpHandle was a contributed class which I know the contributor uses, so it's odd that it would have such a blatant bug. If you're able to test your changes, then a pull request would be accepted.

from python-adb.

thica avatar thica commented on May 20, 2024

Hi,

its tested

`class TcpHandle(object):
"""TCP connection object.

 Provides same interface as UsbHandle but ignores timeout."""

def init(self, serial):
"""Initialize the TCP Handle.
Arguments:
serial: Android device serial of the form host or host:port.

Host may be an IP address or a host name.
"""
if ':' in serial:
  (host, port) = serial.split(':')
  port_int=int(port)  # CTH Code adjusted
else:
  host = serial
  port = 5555
self._serial_number = '%s:%s' % (host, port)

self._connection = socket.create_connection((host, port_int))  # CTH Code adjusted
`

You can easy tell, that the line
port = 5555
indicates a numeric value.

from python-adb.

thica avatar thica commented on May 20, 2024

Sorry just seen, that the default path have to covered as well

`
class TcpHandle(object):
"""TCP connection object.

 Provides same interface as UsbHandle but ignores timeout."""

def init(self, serial):
"""Initialize the TCP Handle.
Arguments:
serial: Android device serial of the form host or host:port.

Host may be an IP address or a host name.
"""
if ':' in serial:
  (host, port) = serial.split(':')
  port_int=int(port)  # CTH Code adjusted
else:
  host = serial
  port = '5555' # CTH Code adjusted
  port_int = 5555 # CTH Code adjusted
self._serial_number = '%s:%s' % (host, port)

self._connection = socket.create_connection((host, port_int)) # CTH Code adjusted

`

from python-adb.

 avatar commented on May 20, 2024

Hi @thica !

In fact socket.create_connection can take a tuple of (str, str) or (str, int).

>>> socket.create_connection(('127.0.0.1', '12800'))
<socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 39774), raddr=('127.0.0.1', 12800)>
>>> socket.create_connection(('127.0.0.1', 12800))
<socket.socket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 39778), raddr=('127.0.0.1', 12800)>

So we do not need to cast port value. 😃

from python-adb.

thica avatar thica commented on May 20, 2024

Hi checked it out, you are right. I am running on an error, as all my strings in my app are unicode, which can't be handled by socket.
socket.create_connection(('127.0.0.1', u'8080'))
Traceback (most recent call last):
File "", line 1, in
File "D:\dev\Kivy27\Python27\lib\socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.error: getaddrinfo() argument 2 must be integer or string

from python-adb.

fahhem avatar fahhem commented on May 20, 2024

You'll need to encode the port as bytes before passing it to TcpHandle then: port.encode('ascii')

from python-adb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.