473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

TcpClient list

I'm making a C# server for flash clients using TcpClients and listeners. I got the whole thing working when using just one TcpClient, I can send to and recieve from it. Now I'm working on a function to broadcast a message to all the TcpClients, which I've added to a List. It says it sent but in fact I don't recieve anything on my flash apps. Does anybody know what's wrong?

Here's the bit of code that broadcasts it, it's just the single client message for each client.

Expand|Select|Wrap|Line Numbers
  1. public void sendToClient(String line)
  2.         {
  3.             NetworkStream clientStream;
  4.             clientStream = activeClient.GetStream();
  5.             ASCIIEncoding encoder = new ASCIIEncoding();
  6.             byte[] buffer = encoder.GetBytes(line + "\0");
  7.  
  8.             clientStream.Write(buffer, 0, buffer.Length);
  9.             clientStream.Flush();
  10.         }
  11.  
  12.         public void broadcast(String line)
  13.         {
  14.                 for (int i = 0; i < connClients.Count; i++)
  15.                 {
  16.                     if (connClients[i].GetStream().CanWrite)
  17.                     {
  18.                         activeClient = connClients[i];
  19.                         sendToClient(line);
  20.                     }
  21.                     else
  22.                     {
  23.                         connClients.Remove(connClients[i]);
  24.                         myInterface.logTxt.AppendText("Client disconnected."+ Environment.NewLine);
  25.                     }
  26.                 }
  27.                 myInterface.logTxt.AppendText("Message broadcasted to " + connClients.Count.ToString() + " clients." + Environment.NewLine);
  28.  
  29.         }
  30.  
Apr 30 '10 #1
2 2964
Plater
7,872 Expert 4TB
Shouldn't your send to client function take in the client object you want to send to?
Do you get any exceptions?
Apr 30 '10 #2
You are right, I've changed the function so it includes the tcpclient object, but although of this it still doesn't get recieved, I don't get any exceptions.
Apr 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on...
2
by: Theo | last post by:
Hi, I am using a tcpclient and a tcplistener to send and receive packets. The client sends a packet and the listener replies with another one. I can send 2 packets and get an answer from the...
3
by: מורדי | last post by:
Hi, I'm writing a client/server application in which the client send a series of screenshots to the server to be saved using the tcpclient. in most cases the first screenshot is transmitted ok...
3
by: Ricardo Quintanilla | last post by:
i had a problem whom i do not know how to explain. i was using a TcpClient (System.Net.Sockets.TcpClient) object to send and receive data to an AS400 socket. Two months ago it started to work...
3
by: Danny Tuppeny | last post by:
Hi all, I'm trying to send a null character as a string delimiter through a TcpClient (code below). It's to connect to this poker bot room: http://games.cs.ualberta.ca/webgames/poker/bots.html...
0
by: Torsten Brasch | last post by:
Hi All and Happy New Year ;) I have a very strange problem with System.Net.Sockets.TcpClient(). For some reason, the number of bytes I can receive is limited to 5460 bytes. I made sure that the...
0
by: Mark | last post by:
Ok, Why is this so hard too do? I have a TCPListener that's working exactly as expected. It fires off a new thread to listen on calling this function. ...
1
by: hamil | last post by:
I am having trouble using the TcpListener and TcpClient classes. At the end of this post is server code that runs, and a class whose purpose is described below. I need to know when the client...
10
by: Jan Vinten | last post by:
Hi all, I got into some trouble trying to bind to a specific IP address. Code: Private mobjClient As TcpClient mobjClient = New TcpClient(IPAddress.Parse("10.16.104.87").ToString, 8892)
5
by: puzzlecracker | last post by:
It looks like i need to get IPEndPoint first, but I cannot figure out from msdn the eventual obtainment of machine name and port number. Please suggest a solution. Thanks
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.