Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. multi tcp clients

multi tcp clients

Scheduled Pinned Locked Moved C#
tutorialcsharpsysadmin
5 Posts 3 Posters 36 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    darinka
    wrote on last edited by
    #1

    Hello everyone, I try to connect a pc to some esp32 arudino boards using tcp sockets the idea is that on the each esp board I open a server that accapt the pc( client ) request and also a client that is used to do all data traffic between the pc and esp the pc and the board use the some router as AP i wrote some thing like that using Jyhton Now i want to do the some for other project but on the PC I run a VS2022 C# program that connect to the esp boards but i don't know how to do it . Can someone show me the road ( an example will be great ) Regards Doron

    OriginalGriffO J 2 Replies Last reply
    0
    • D darinka

      Hello everyone, I try to connect a pc to some esp32 arudino boards using tcp sockets the idea is that on the each esp board I open a server that accapt the pc( client ) request and also a client that is used to do all data traffic between the pc and esp the pc and the board use the some router as AP i wrote some thing like that using Jyhton Now i want to do the some for other project but on the PC I run a VS2022 C# program that connect to the esp boards but i don't know how to do it . Can someone show me the road ( an example will be great ) Regards Doron

      OriginalGriffO Online
      OriginalGriffO Online
      OriginalGriff
      wrote on last edited by
      #2

      You are going to have to give us a lot more detail than that - we have no idea what you have tired, where you are stuck, or what help you might need - if you have a working example, most developers should be able to alter it to fit the new circumstances, so we are at a loss to know what you expect from us that will help you get there.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      D 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        You are going to have to give us a lot more detail than that - we have no idea what you have tired, where you are stuck, or what help you might need - if you have a working example, most developers should be able to alter it to fit the new circumstances, so we are at a loss to know what you expect from us that will help you get there.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        D Offline
        D Offline
        darinka
        wrote on last edited by
        #3

        Hi May be is was not clear , I don't have code written yet. i want to get the idea how to create and manage many client sockets on my pc so i can select the socket i will send the data to by using the ip or other index Doron

        1 Reply Last reply
        0
        • D darinka

          Hello everyone, I try to connect a pc to some esp32 arudino boards using tcp sockets the idea is that on the each esp board I open a server that accapt the pc( client ) request and also a client that is used to do all data traffic between the pc and esp the pc and the board use the some router as AP i wrote some thing like that using Jyhton Now i want to do the some for other project but on the PC I run a VS2022 C# program that connect to the esp boards but i don't know how to do it . Can someone show me the road ( an example will be great ) Regards Doron

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          Doesn't matter how you 'think' about the design the following is true. For TCP sockets there is always a 'server' and a 'client'. The 'server' creates a listener port and waits for a connection. The 'client' opens a socket to the server. So the client is the one that initiates the connection. After a connection is created either side can send and receive requests. Although often the client is the one that sends most requests. The above also means that the server must have an addressable IP address. Probably in your situation that will not matter but it does mean you will need to figure out what the servers IP address is. ----------------------------- Now for your actual code whether your want the pc or arudino to be the server is up to you. (I know very little about the second but I expect it can act as both a server and client.) However I suggest that you start your learning experience using the PC only. So you will have two programs that run on your PC. One is the server. One is the client. You can google for examples of writing code exactly like that in C#. After you have tested that a bit then I suggest again only on the PC that you simulate what you want to actually do using the sample code. So for example if you want to send a specific command to the arudino then add code to do that in the PC code (client probably) and then respond in a pseudo way on the other side of the PC code. You might also want to figure out how to analyze problems while you are developing this. So for example you might do the following - PC server code to simulate arudino - Command received: Health check. Returns 'ok' - PC client code to send command - Command send: Health check - Use Console.WriteLine() to write the command to send (all information) - Use socket code to send it - Use socket code to recieve response - Use Console.WriteLine to write the response (all information.) You should also experiment with what happens when the IP address is wrong and what happens if the server is not running. ----------------------------------------------------------------------- As additional suggest for quite a bit in the future for a full application relying on Console.WriteLine() is not workable. So investigate 'logging'. You should not do this until you are comfortable with sockets.

          D 1 Reply Last reply
          0
          • J jschell

            Doesn't matter how you 'think' about the design the following is true. For TCP sockets there is always a 'server' and a 'client'. The 'server' creates a listener port and waits for a connection. The 'client' opens a socket to the server. So the client is the one that initiates the connection. After a connection is created either side can send and receive requests. Although often the client is the one that sends most requests. The above also means that the server must have an addressable IP address. Probably in your situation that will not matter but it does mean you will need to figure out what the servers IP address is. ----------------------------- Now for your actual code whether your want the pc or arudino to be the server is up to you. (I know very little about the second but I expect it can act as both a server and client.) However I suggest that you start your learning experience using the PC only. So you will have two programs that run on your PC. One is the server. One is the client. You can google for examples of writing code exactly like that in C#. After you have tested that a bit then I suggest again only on the PC that you simulate what you want to actually do using the sample code. So for example if you want to send a specific command to the arudino then add code to do that in the PC code (client probably) and then respond in a pseudo way on the other side of the PC code. You might also want to figure out how to analyze problems while you are developing this. So for example you might do the following - PC server code to simulate arudino - Command received: Health check. Returns 'ok' - PC client code to send command - Command send: Health check - Use Console.WriteLine() to write the command to send (all information) - Use socket code to send it - Use socket code to recieve response - Use Console.WriteLine to write the response (all information.) You should also experiment with what happens when the IP address is wrong and what happens if the server is not running. ----------------------------------------------------------------------- As additional suggest for quite a bit in the future for a full application relying on Console.WriteLine() is not workable. So investigate 'logging'. You should not do this until you are comfortable with sockets.

            D Offline
            D Offline
            darinka
            wrote on last edited by
            #5

            Thanks for help

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups