# Programming Socketserver with C#

**URL:** <https://forum.universal-robots.com/t/programming-socketserver-with-c/18211>\
**Category:** Robot Communication\
**Created:** [December 16, 2021, 1:04pm UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211 "2021-12-16T13:04:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![eikefranke](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@eikefranke](https://forum.universal-robots.com/u/eikefranke)\
**Post date:** [December 16, 2021, 1:04pm UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211/1 "2021-12-16T13:04:22Z")

</div>

Hey Guys.

I need a SocketServer-Programm that toke informations frome a comandline input (that comandline will start the Server) and save the informations (it will be an text like “Start testing”)

than the Programm will transform this fix Text´s in an array

after that conect with the UR. send him this informations (in the moment i need to send an bit-array [1,1,1,1] later some Text needed to be included)  
And after send this Informations to the UR, the UR will send some informations back.

after this backinformation, the Server needed to create an error information that have this information from the UR in it and than the server closed.

And also a other question: how can i Program an DashboardServer or Dashboardclient with C#?  
And also can i take an Socketserver and a Dashboardserver in one Programm?  
And can a Cobot handel a Dashboardserverconnection and a Socketserver over only one LAN-Cable in the same time?

how can i finde some understandebal informations how to work with socketserver?

Thanks for your help.

i have only an start that is followed skriptet (i have copyed out from Google, but the first test shows it works, if you have some other solutens please let me know):

static void Main(string args]  
{  
string sHostIpAddress = “10.3.225.1”;  
int nPort = 21;

IPAddress = IPAddress.Parse(sHostIpAddress);  
IPEndPoint localEndPoint = new IPEndPoint[ipAddress, nPort);

---

<div class="post-metadata">

**Author:** ![androidflorent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/androidflorent/32/3314_2.png) [@androidflorent](https://forum.universal-robots.com/u/androidflorent)\
**Post date:** [December 16, 2021, 5:02pm UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211/2 "2021-12-16T17:02:27Z")

</div>

Hi,

Yes you can open several connections between your C# program and your robot.  
You can implement the Dashboard server protocol yourself: instantiate a TcpClient, write the commands and parse the return.

You can also use a library that has already implemented this for you, for example : [https://underautomation.com](https://underautomation.com) (This commercial library is on Nugget, the showcases are open source on Github, all protocols are implemented in .NET : Dashboard server, primary interface, variable reading, file manipulation, …)

```auto
using UnderAutomation.UniversalRobots;
...
var ur = new UR();
ur.Connect(“10.3.225.1”);
ur.PowerOn();
ur.ReleaseBrake();
ur.LoadProgram("prg1.urp");
ur.Play();

```

---

<div class="post-metadata">

**Author:** ![eikefranke](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@eikefranke](https://forum.universal-robots.com/u/eikefranke)\
**Post date:** [December 17, 2021, 6:56am UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211/3 "2021-12-17T06:56:43Z")

</div>

Thanks for the first help for the Dashboard.

Now i only have the problem how to writh a socketServer witch starts with sending data .  
ii have big problems to read and interpred C# so i do not understand the commands and can not handle them well.

So any body can help me with a socketserver witch start sending, and then start listening?  
it is also possible to writh in C or Python.

thanks for all your help

---

<div class="post-metadata">

**Author:** ![eikefranke](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@eikefranke](https://forum.universal-robots.com/u/eikefranke)\
**Post date:** [December 17, 2021, 11:34am UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211/4 "2021-12-17T11:34:31Z")

</div>

can i also send “play” as Bite-code to the UR?

---

<div class="post-metadata">

**Author:** ![androidflorent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/androidflorent/32/3314_2.png) [@androidflorent](https://forum.universal-robots.com/u/androidflorent)\
**Post date:** [December 17, 2021, 12:16pm UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211/5 "2021-12-17T12:16:10Z")

</div>

I don’t understand your question.  
Maybe this would help, you can also send raw custom dashboard commands :

```auto
ur.SendCustomDashboardCommand("play");

```

---

<div class="post-metadata">

**Author:** ![eikefranke](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@eikefranke](https://forum.universal-robots.com/u/eikefranke)\
**Post date:** [December 17, 2021, 12:33pm UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211/6 "2021-12-17T12:33:42Z")

</div>

i mean: How can i do this without the UnderAutomation.UniversalRoborts Lib.

---

<div class="post-metadata">

**Author:** ![bba](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/bba/32/555_2.png) [@bba](https://forum.universal-robots.com/u/bba)\
**Post date:** [December 21, 2021, 7:33pm UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211/7 "2021-12-21T19:33:07Z")

</div>

Hi,

A ‘C’ library for communicating to the UR robot does not exist (at least I have never seen one), so I would not target the C language. There is the C# SDK and it is a commercial product so it probably comes with some support. I would take the advice of androidflorent.

If you want to gain a general understanding of how to remotely control the robot then I would start with this document :  
[Remote operation of robots](https://www.universal-robots.com/articles/ur/interface-communication/remote-operation-of-robots/)  
It will point you to Python examples.

---

<div class="post-metadata">

**Author:** ![androidflorent](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/androidflorent/32/3314_2.png) [@androidflorent](https://forum.universal-robots.com/u/androidflorent)\
**Post date:** [December 24, 2021, 10:38am UTC](https://forum.universal-robots.com/t/programming-socketserver-with-c/18211/8 "2021-12-24T10:38:03Z")

</div>

@eikefranke try this code :

```auto
        System.Net.Sockets.TcpClient tcp = null;
        try
        {
            tcp = new System.Net.Sockets.TcpClient();
            tcp.ReceiveTimeout = 2000;
            tcp.SendTimeout = 500;
            tcp.Connect("10.3.225.1", 29999);
            using (var stream = tcp.GetStream())
            {
                using (var reader = new System.IO.StreamReader(stream))
                {                    
                    reader.ReadLine();// line received after connection
                    var bytes = System.Text.Encoding.UTF8.GetBytes($"play\r\n");
                    stream.Write(bytes, 0, bytes.Length);
                    var answer = reader.ReadLine();
                    Console.WriteLine(answer);
                }
            }
        }
        finally
        {
            tcp?.Close();
        }

```
