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. multiple socket connection

multiple socket connection

Scheduled Pinned Locked Moved C#
tutorialcsharpsysadminhelp
3 Posts 3 Posters 0 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.
  • A Offline
    A Offline
    Ajithevn
    wrote on last edited by
    #1

    Hi all, Can somebody help me on how to create multiple connection to different server using ip/port at the same time and receive data. I have a program in C# but it's only working for 1 connection. Please help me or redirect me for a tutorial on multiple socket programming in C#. I'm new to this thing.

    R J 2 Replies Last reply
    0
    • A Ajithevn

      Hi all, Can somebody help me on how to create multiple connection to different server using ip/port at the same time and receive data. I have a program in C# but it's only working for 1 connection. Please help me or redirect me for a tutorial on multiple socket programming in C#. I'm new to this thing.

      R Offline
      R Offline
      Rick van Woudenberg
      wrote on last edited by
      #2

      Multithreading will do the trick. Just open a each TcpListener or Socket(udp) connection in a seperate thread.

      1 Reply Last reply
      0
      • A Ajithevn

        Hi all, Can somebody help me on how to create multiple connection to different server using ip/port at the same time and receive data. I have a program in C# but it's only working for 1 connection. Please help me or redirect me for a tutorial on multiple socket programming in C#. I'm new to this thing.

        J Offline
        J Offline
        Jimmanuel
        wrote on last edited by
        #3

        You've shown that you have the code to connect from one machine to another. Just duplicate it. Nothing says that you can have only one socket open at a time so it's fine to do something like this:

        open Socket A
        open Socket B
        . . .
        read something from A
        . . .
        write the data to B
        . . .
        close A
        close B

        you don't even need to close the sockets for each operation. You can leave them open for the lifetime of the process if you need to instead of opening them and closing them each time that you need them. Unfortunately I don't have any links to tutorials on multiple socket programming; i doubt that any really exist. There's no real difference between using one socket and using multiple sockets except that in the former you see things like Socket and in the latter you'll see things like List ( Socket ).

        :badger:

        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