the above c sharp code will send client desktop images to server . it works for single client . we want to implement this for multiple client. please provide help to implement it. SERVER code:-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.Remoting;
using System.Linq;
using System.Text;
using System.Net .Sockets ;
using System.Windows.Forms;
using System.Threading ;
using System.Runtime.Serialization.Formatters.Binary;
using System.Net;
namespace simpleserver
{
public partial class Form2 : Form
{
private readonly int port;
private TcpClient client;
private TcpListener server;
//static public int MAX_CONN = 5;
private NetworkStream mainstream;
//private string ipList;
//TcpListener myList = null;
//static int thrd = -1;
private readonly Thread Listening;
private readonly Thread Getimg;
public Form2(int Port)
{
port = Port;
client = new TcpClient();
Listening = new Thread(StartListening);
Getimg = new Thread(ReceiveImage);
InitializeComponent();
}
private void StartListening()
{
while (!client.Connected)
{
//ipList = new string\[MAX\_CONN\];
//myList = new TcpListener(hostIP, hostPort);
//myList.Start();
server.Start();
client = server.AcceptTcpClient();
}
Getimg.Start();
}
private void stop()
{
server.Stop();
client = null;
if (Listening .IsAlive )Listening .Abort ();
if ( Getimg .IsAlive )Getimg .Abort ();
}
private void ReceiveImage()
{
BinaryFormatter binformatter = new BinaryFormatter();
while (client.Connected)
{
mainstream = client.GetStream();
pictureBox1.Image =(Image ) binformatter.Deserialize(mainstream);
// pictureBox2 .Image =(Image )binformatter .Deserialize (mainstream );
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
server = new TcpListener(IPAddress .Any ,port );
Listening .Start ();
}