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