# \[SOLVED\] Telnet Comm through socket connection

**URL:** <https://forum.universal-robots.com/t/solved-telnet-comm-through-socket-connection/1372>\
**Category:** URScript\
**Created:** [November 28, 2017, 7:24pm UTC](https://forum.universal-robots.com/t/solved-telnet-comm-through-socket-connection/1372 "2017-11-28T19:24:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuel.paxton](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@samuel.paxton](https://forum.universal-robots.com/u/samuel.paxton)\
**Post date:** [November 28, 2017, 7:24pm UTC](https://forum.universal-robots.com/t/solved-telnet-comm-through-socket-connection/1372/1 "2017-11-28T19:24:44Z")

</div>

Hi all,

I am trying to login to an external device via Telnet socket communication that has a user/pass field, but without success. Currently, I can login onto the device (on a Unix machine) with the `telnet` command. Upon successful connection, I get this response, where `<input>` is my input for each field:

`telnet xxx.xxx.xxx.xxx 23`  
`User:<input>`  
`Pass:<input>`

And I am successfully logged on.

I am trying to mimic this with URScript (abridged version):  
`
1 socket_open(“xxx.xxx.xxx.xxx”,23) #Open socket at Telnet port
2 userPrompt = socket_read_string() #Reads "User: "
3 didSendUser = socket_send_line(“username”) #Send username with newline appended
4 passPrompt = socket_read_string() #Reads "Password: "
5 didSendPass = socket_send_line(“password”) #Send password with newline appended
`

Currently, the program reaches line 4, where it indefinitely times out. I’ve checked the value of `userPrompt`, which is as expected: "User: ". Line 3 also executes successfully, as `didSendUser` is True.

It seems as though the device is not processing my input, since the device never sends "Password: " back to the program. This makes me think I’ll need a separate thread to handle output, but I want to make sure that is correct before I go through with it.

Thanks in advance.

**_EDIT: PLEASE READ:_**  
As it turns out, telnet requires not only a newline `\n`, but also a carriage return `\r` right before hand. For example: `"myString\r\n"`

~~**That said** , the URScript implementation still hangs up after sending the username. I’ve confirmed my above solution works in a python implementation, so I’ve temporarily resorted to XMLRPC implementation using a python server. I will occasionally troubleshoot the URScript implementation and update if I find a solution.~~

**_SOLUTION:_** This function works for sending string commands via Telnet:  
`
def telnet_send(str):
    socket_send_string(str)
    socket_send_byte(13) #send carriage return (CR)
    socket_send_byte(10) #send line feed (LF)
end`

---

<div class="post-metadata">

**Author:** ![samuel.paxton](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@samuel.paxton](https://forum.universal-robots.com/u/samuel.paxton)\
**Post date:** [November 30, 2017, 7:09pm UTC](https://forum.universal-robots.com/t/solved-telnet-comm-through-socket-connection/1372/2 "2017-11-30T19:09:27Z")

</div>

Please read my edit.

---

<div class="post-metadata">

**Author:** ![jacques.bouvier](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@jacques.bouvier](https://forum.universal-robots.com/u/jacques.bouvier)\
**Post date:** [December 1, 2017, 2:32pm UTC](https://forum.universal-robots.com/t/solved-telnet-comm-through-socket-connection/1372/3 "2017-12-01T14:32:00Z")

</div>

for my application with telnet command , I use URscript for login User & Password :

for login user :  
socket\_send\_string(“MyUser”,“TelnetSocket”)  
socket\_send\_byte(13,“TelnetSocket”)  
socket\_send\_byte(0,“TelnetSocket”)  
string\_user=socket\_read\_string(“TelnetSocket”)

---

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [December 1, 2017, 2:35pm UTC](https://forum.universal-robots.com/t/solved-telnet-comm-through-socket-connection/1372/4 "2017-12-01T14:35:16Z")

</div>

> [@jacques.bouvier](#):
>
> socket\_send\_string(“MyUser”,“TelnetSocket”)
> 
> socket\_send(13,“TelnetSocket”)
> 
> socket\_send(0,“TelnetSocket”)
> 
> string\_user=socket\_read\_string(“TelnetSocket”)

Did you mean `socket_send_byte(10,“TelnetSocket”)`, hence byte 13 = CR, 10 = LF?

---

<div class="post-metadata">

**Author:** ![jacques.bouvier](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@jacques.bouvier](https://forum.universal-robots.com/u/jacques.bouvier)\
**Post date:** [December 1, 2017, 2:49pm UTC](https://forum.universal-robots.com/t/solved-telnet-comm-through-socket-connection/1372/5 "2017-12-01T14:49:11Z")

</div>

I had the same problem with telnet with “\n”.  
I mean :  
1°) socket\_send\_byte(13,“TelnetSocket”) = CR  
2°) socket\_send\_byte(0,“TelnetSocket”)

---

<div class="post-metadata">

**Author:** ![samuel.paxton](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@samuel.paxton](https://forum.universal-robots.com/u/samuel.paxton)\
**Post date:** [December 1, 2017, 5:11pm UTC](https://forum.universal-robots.com/t/solved-telnet-comm-through-socket-connection/1372/6 "2017-12-01T17:11:05Z")

</div>

Hi Jaques,

As @jbm said, using `socket_send_byte(13)` followed by `socket_send_byte(10)` seems to work great. Thanks for the suggestion. I’ll mark that as the solution in my original post.
