Click here to Skip to main content
15,890,186 members
Home / Discussions / C#
   

C#

 
GeneralRe: Writing and Reading on MemoryStream? Pin
Scott Serl20-Apr-05 8:29
Scott Serl20-Apr-05 8:29 
GeneralRe: Writing and Reading on MemoryStream? Pin
Snowjim20-Apr-05 8:40
Snowjim20-Apr-05 8:40 
GeneralRe: Writing and Reading on MemoryStream? Pin
Scott Serl20-Apr-05 11:04
Scott Serl20-Apr-05 11:04 
GeneralRe: Writing and Reading on MemoryStream? Pin
Snowjim20-Apr-05 11:42
Snowjim20-Apr-05 11:42 
GeneralRe: Writing and Reading on MemoryStream? Pin
Scott Serl21-Apr-05 8:22
Scott Serl21-Apr-05 8:22 
GeneralCrystalReports From Pull -> Push Pin
V.18-Apr-05 23:49
professionalV.18-Apr-05 23:49 
GeneralFilling the Textbox Pin
Anonymous18-Apr-05 23:36
Anonymous18-Apr-05 23:36 
Generalplease help me with this Pin
snouto18-Apr-05 23:28
snouto18-Apr-05 23:28 
i succeeded to create multithreaded server that can accept multiple clients connection while running alright and every client can send to the server messages but when i try to send from the server message for all clients connected now it through and exception and it doesn't send anything i want to handle the connection for all users to send them back messages for all of them something like hashtable to handle tcp clients who are now connected any one knows how to do it .

my code is

<br />
private Hashtable connections;		<br />
		public void runserver()<br />
		{<br />
			connections = new Hashtable();<br />
			TcpListener server;<br />
			try<br />
			{<br />
				server = new TcpListener(5151);<br />
				server.Start();<br />
				//loop until recieveing connection request from the clients<br />
				do<br />
				{<br />
					try<br />
					{<br />
						//inform at the server side that it is waiting for connection<br />
						//from clients<br />
						if(counter < 1 || counter == 1)<br />
						{<br />
							generalchat.Items.Add("Waiting for connection");<br />
						}<br />
						//intialize new socket connection upon client request<br />
				<br />
						Socket connection = server.AcceptSocket();<br />
						//////////////////////////////////////////////////////<br />
						//here what did you told me... you mean like that <br />
						Thread Anotherthread = new Thread(new <br />
							ThreadStart(HandleConnection));<br />
						connections.Add(Anotherthread, connection);<br />
						++counter;<br />
						generalchat.Items.Add("Connection " + counter + " Recieved");<br />
						Anotherthread.Start();<br />
					}<br />
					catch (Exception)<br />
					{<br />
						break;<br />
					}<br />
				} while (true);<br />
			}<br />
			catch (System.Exception caught)<br />
			{<br />
				MessageBox.Show(caught.Message);<br />
			}<br />
		}<br />
		private Hashtable myclients;<br />
		private TcpClient clients;<br />
		private void HandleConnection()<br />
		{<br />
			Socket connection = connections[Thread.CurrentThread] as Socket;<br />
			//intialize new network stream connection<br />
			NetworkStream socketstream = new NetworkStream(connection);<br />
			//intialize new binary reader and binary writer to the network<br />
			BinaryReader reader = new BinaryReader(socketstream);<br />
			BinaryWriter writer = new BinaryWriter(socketstream);<br />
			//inform the user that there was new client connection<br />
			writer.Write("Server : " + "Welcome Client");<br />
			myclients = new Hashtable();<br />
			clients = new TcpClient();<br />
			myclients.Add(connection,clients.GetStream());<br />
			string message = "";<br />
			do<br />
			{<br />
				message = reader.ReadString();<br />
				if(message == "terminate")<br />
				{<br />
					generalchat.Items.Add("Client Terminated the connection");<br />
					--counter;<br />
					break;<br />
				}<br />
				if(message.IndexOf("@") != -1)<br />
				{<br />
					clientTable.Add(this.flush(message),splittedwords[1].ToString());<br />
					generalchat.Items.Add(this.flush(message) + " : Already Connected");<br />
				}else<br />
					generalchat.Items.Add(message);<br />
<br />
			} while (connection.Connected);<br />
		}<br />

any one knows how please

Miss With The Best And Die Like The Rest
GeneralRe: please help me with this Pin
S. Senthil Kumar19-Apr-05 0:52
S. Senthil Kumar19-Apr-05 0:52 
GeneralTransparent ListBoxes Pin
zagzagzag18-Apr-05 23:24
zagzagzag18-Apr-05 23:24 
GeneralRe: Transparent ListBoxes Pin
Anonymous19-Apr-05 1:05
Anonymous19-Apr-05 1:05 
GeneralRe: Transparent ListBoxes Pin
Dave Kreskowiak19-Apr-05 4:19
mveDave Kreskowiak19-Apr-05 4:19 
GeneralRe: Transparent ListBoxes Pin
zagzagzag19-Apr-05 9:10
zagzagzag19-Apr-05 9:10 
GeneralMusic Programming Pin
Deniz Oflaz18-Apr-05 23:11
Deniz Oflaz18-Apr-05 23:11 
GeneralRe: Music Programming Pin
pjc*19-Apr-05 3:27
pjc*19-Apr-05 3:27 
GeneralRe: Music Programming Pin
RNEELY19-Apr-05 4:13
RNEELY19-Apr-05 4:13 
GeneralCreating OdbcDataAdapter object with Select statement that has spaces in the fileName Pin
chukkykzn18-Apr-05 22:58
chukkykzn18-Apr-05 22:58 
GeneralHigh CPU usage when using Toolbar Pin
MasudM18-Apr-05 22:24
MasudM18-Apr-05 22:24 
GeneralHelp -- TreeView, How to Sort only a Part of TreeView Nodes Pin
Umair Tariq18-Apr-05 21:18
Umair Tariq18-Apr-05 21:18 
GeneralRe: Help -- TreeView, How to Sort only a Part of TreeView Nodes Pin
CStiefeling19-Apr-05 8:30
CStiefeling19-Apr-05 8:30 
GeneralRe: Help -- TreeView, How to Sort only a Part of TreeView Nodes Pin
Umair Tariq19-Apr-05 20:41
Umair Tariq19-Apr-05 20:41 
GeneralRe: Help -- TreeView, How to Sort only a Part of TreeView Nodes Pin
CStiefeling20-Apr-05 11:59
CStiefeling20-Apr-05 11:59 
GeneralRe: Help -- TreeView, How to Sort only a Part of TreeView Nodes Pin
Umair Tariq20-Apr-05 20:00
Umair Tariq20-Apr-05 20:00 
GeneralDrawing area objects on top of Image Pin
Lyot_be18-Apr-05 20:56
Lyot_be18-Apr-05 20:56 
GeneralRe: Drawing area objects on top of Image Pin
MoustafaS19-Apr-05 4:36
MoustafaS19-Apr-05 4:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.