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. Need to Learn that How to send message to Particular client

Need to Learn that How to send message to Particular client

Scheduled Pinned Locked Moved C#
csharpwinformssysadmintoolstutorial
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.
  • M Offline
    M Offline
    M Riaz Bashir
    wrote on last edited by
    #1

    Hi, Kindly let me know that, How may I send message to particular client. if four client are already connected. I want to send message to fourth-one. Following Server-side script is working very good but it sends to every one. please tell me where will I have to change following script to send message to particular client. Thank you Script is here:

    using System;
    using System.Windows.Forms;
    using System.Net;
    using System.Net.Sockets;

    namespace DefaultNamespace
    {
    /// <summary>
    /// Description of SocketServer.
    /// </summary>
    public class SocketServer : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.RichTextBox richTextBoxReceivedMsg;
    private System.Windows.Forms.TextBox textBoxPort;
    private System.Windows.Forms.Label label5;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.TextBox textBoxMsg;
    private System.Windows.Forms.Button buttonStopListen;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.RichTextBox richTextBoxSendMsg;
    private System.Windows.Forms.TextBox textBoxIP;
    private System.Windows.Forms.Button buttonStartListen;
    private System.Windows.Forms.Button buttonSendMsg;
    private System.Windows.Forms.Button buttonClose;

    	const int MAX\_CLIENTS = 10;
    	
    	public AsyncCallback pfnWorkerCallBack ;
    	private  Socket m\_mainSocket;
    	private  Socket \[\] m\_workerSocket = new Socket\[10\];
    	private int m\_clientCount = 0;
    	
    	public SocketServer()
    	{
    		//
    		// The InitializeComponent() call is required for Windows Forms designer support.
    		//
    		InitializeComponent();
    		
    		// Display the local IP address on the GUI
    		textBoxIP.Text = GetIP();
    	}
    	
    	\[STAThread\]
    	public static void Main(string\[\] args)
    	{
    		Application.Run(new SocketServer());
    	}
    	
    	#region Windows Forms Designer generated code
    	/// <summary>
    	/// This method is required for Windows Forms designer support.
    	/// Do not change the method contents inside the source code editor. The Forms designer might
    	/// not be able to load this method if it was changed manually.
    	/// </summary>
    	private void InitializeComponent() {
    		this.buttonClose = new System.Windows.Forms.Button();
    		this.buttonSendMsg = new System.Windows.Forms.Button();
    		this.buttonStartListen = new System.Windows.Forms.Button();
    		this.textBoxIP = new System.Windows.Forms.TextBox();
    		t
    
    C 1 Reply Last reply
    0
    • M M Riaz Bashir

      Hi, Kindly let me know that, How may I send message to particular client. if four client are already connected. I want to send message to fourth-one. Following Server-side script is working very good but it sends to every one. please tell me where will I have to change following script to send message to particular client. Thank you Script is here:

      using System;
      using System.Windows.Forms;
      using System.Net;
      using System.Net.Sockets;

      namespace DefaultNamespace
      {
      /// <summary>
      /// Description of SocketServer.
      /// </summary>
      public class SocketServer : System.Windows.Forms.Form
      {
      private System.Windows.Forms.Label label3;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.RichTextBox richTextBoxReceivedMsg;
      private System.Windows.Forms.TextBox textBoxPort;
      private System.Windows.Forms.Label label5;
      private System.Windows.Forms.Label label4;
      private System.Windows.Forms.TextBox textBoxMsg;
      private System.Windows.Forms.Button buttonStopListen;
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.RichTextBox richTextBoxSendMsg;
      private System.Windows.Forms.TextBox textBoxIP;
      private System.Windows.Forms.Button buttonStartListen;
      private System.Windows.Forms.Button buttonSendMsg;
      private System.Windows.Forms.Button buttonClose;

      	const int MAX\_CLIENTS = 10;
      	
      	public AsyncCallback pfnWorkerCallBack ;
      	private  Socket m\_mainSocket;
      	private  Socket \[\] m\_workerSocket = new Socket\[10\];
      	private int m\_clientCount = 0;
      	
      	public SocketServer()
      	{
      		//
      		// The InitializeComponent() call is required for Windows Forms designer support.
      		//
      		InitializeComponent();
      		
      		// Display the local IP address on the GUI
      		textBoxIP.Text = GetIP();
      	}
      	
      	\[STAThread\]
      	public static void Main(string\[\] args)
      	{
      		Application.Run(new SocketServer());
      	}
      	
      	#region Windows Forms Designer generated code
      	/// <summary>
      	/// This method is required for Windows Forms designer support.
      	/// Do not change the method contents inside the source code editor. The Forms designer might
      	/// not be able to load this method if it was changed manually.
      	/// </summary>
      	private void InitializeComponent() {
      		this.buttonClose = new System.Windows.Forms.Button();
      		this.buttonSendMsg = new System.Windows.Forms.Button();
      		this.buttonStartListen = new System.Windows.Forms.Button();
      		this.textBoxIP = new System.Windows.Forms.TextBox();
      		t
      
      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      M Riaz Bashir wrote:

      for(int i = 0; i < m_clientCount; i++){ if(m_workerSocket[i] != null){ if(m_workerSocket[i].Connected){ m_workerSocket[i].Send (byData); } } }

      I have two reasons to believe that you really have not the slightest idea what you're doing. 1 - you posted a ton of useless boilerplate code 2 - if you can't work out from this how to send to only one user, then you should take a class, read a book, do SOMETHING to create a basic understanding of programming before you play with other people's code. I assume you're playing with something you found online to teach yourself, I can't see how this could be work or school. So, take a step back, buy a book, and learn how to read some basic code before you start trying to mash up other people's.

      Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

      M 1 Reply Last reply
      0
      • C Christian Graus

        M Riaz Bashir wrote:

        for(int i = 0; i < m_clientCount; i++){ if(m_workerSocket[i] != null){ if(m_workerSocket[i].Connected){ m_workerSocket[i].Send (byData); } } }

        I have two reasons to believe that you really have not the slightest idea what you're doing. 1 - you posted a ton of useless boilerplate code 2 - if you can't work out from this how to send to only one user, then you should take a class, read a book, do SOMETHING to create a basic understanding of programming before you play with other people's code. I assume you're playing with something you found online to teach yourself, I can't see how this could be work or school. So, take a step back, buy a book, and learn how to read some basic code before you start trying to mash up other people's.

        Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

        M Offline
        M Offline
        Moim Hossain
        wrote on last edited by
        #3

        Christian Graus wrote:

        I have two reasons to believe that you really have not the slightest idea what you're doing

        :laugh: I agree

        Moim Hossain R&D Project Manager BlueCielo ECM Solutions BV

        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