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. Socket Connections

Socket Connections

Scheduled Pinned Locked Moved C#
sysadminxmlhelptutorialquestion
2 Posts 2 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.
  • B Offline
    B Offline
    budidharma
    wrote on last edited by
    #1

    I've been reading about sockets for the past two days. I've got a few questions, mostly relating to the differences between synchronous and asynchronous behavior. I'm writing the following application: Data Server: Must be able to have multiple clients connected. Once a client has connected, it must be able to recieve data from that client and return data to that client at all times. It will need to be able to recieve and processing data from more than one client at a time. Data Client: The client simply connects, then sends data either at intervals (1-4 XML formated data strings per second), or manually when a user chooses. The data needs to be sent to the server (while connected) and then the client needs to wait for a response. From what I've read, using the TcpListener/TcpClient interface is synchronous: If there are multiple clients connected - if one client is sending data, another cannot be sending data. But if I use a threaded socket interface using asynchornous methods, then data from multiple clients can be recieved at the same time. Am I understanding this correctly? Can someone recommend a good solution for this? Do I need to use the asynchronous socket methods? Do I need to use threads? I've found many examples of tcp/client interfaces, but most of the authors don't explain the benefits/limitations of their code - so it's hard to know if I should base my work from what they're presenting. Does anyone know of a good tutorial that will meet my needs for this project? ... as always, Thanks for the help.

    R 1 Reply Last reply
    0
    • B budidharma

      I've been reading about sockets for the past two days. I've got a few questions, mostly relating to the differences between synchronous and asynchronous behavior. I'm writing the following application: Data Server: Must be able to have multiple clients connected. Once a client has connected, it must be able to recieve data from that client and return data to that client at all times. It will need to be able to recieve and processing data from more than one client at a time. Data Client: The client simply connects, then sends data either at intervals (1-4 XML formated data strings per second), or manually when a user chooses. The data needs to be sent to the server (while connected) and then the client needs to wait for a response. From what I've read, using the TcpListener/TcpClient interface is synchronous: If there are multiple clients connected - if one client is sending data, another cannot be sending data. But if I use a threaded socket interface using asynchornous methods, then data from multiple clients can be recieved at the same time. Am I understanding this correctly? Can someone recommend a good solution for this? Do I need to use the asynchronous socket methods? Do I need to use threads? I've found many examples of tcp/client interfaces, but most of the authors don't explain the benefits/limitations of their code - so it's hard to know if I should base my work from what they're presenting. Does anyone know of a good tutorial that will meet my needs for this project? ... as always, Thanks for the help.

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      I have recently written something similar to you Data Server, and it works as follows. In the main thread I spawn a new thread which just listens (using TcpListener) for incoming TCP connections. When a new connection arrives the TcpListener passes a Socket object on the way out of AcceptSocket. I pass this socket to a ThreadPool worker thread which will handle the rest of the communication for that connection, meanwhile the listener thread loops back and waits for another socket connection. That provides a straight-foward multithreaded server approach - the server can communicate with several clients at the same time with each conversation in isolation from the others. As far as the client goes, that should be just straight forward socket stuff using either Socket or TcpClient. It's gone midnight here and I'm going to bed, but if you'd like me to send some sample source code through drop me a line and I'll do it tomorrow. Rob Philpott.

      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