#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0

    Socket on Python


    Hi!

    I'm new to this forum and to python. I started to learn python because I want to create automated scripts to control a remote device via TCP\IP.

    I've already created a simple server\client code and tested it with remote computers.

    Next step is to connect to a remote device using the following code (it works if I connect to a server created by me):

    import socket
    import time
    import sys

    print ('INFO: Creating Socket')
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    ip_addr = "10.20.11.5"
    port_addr = 5000

    print ('INFO: Connecting to server')
    s.settimeout(5)
    sta = time.clock()
    s.connect((ip_addr, int(port_addr)))

    #init_msg=(":TCP_START_BY_LABVIEW")
    #s.send(bytes(init_msg,'UTF-8'))

    # Listen for welcome
    data = s.recv(4096).decode()


    It returns a Time Out error:

    INFO: Creating Socket
    INFO: Connecting to server
    Traceback (most recent call last):
    File "C:\Python33\1\Client.py", line 25, in <module>
    s.connect((ip_addr, int(port_addr)))
    socket.timeout: timed out

    Is there someone here who developed similar code comment on what might be wrong with my approach?

    Thanks for looking!

    Reyand.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,714
    Rep Power
    4273
    First thing to check is if the device is really listening on that IP address on port 5000. Can you try connecting with something like telnet and see if it responds?
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    2
    Rep Power
    0
    it does respond to connection to it at the same port and IP by a console application provided with it.

IMN logo majestic logo threadwatch logo seochat tools logo