c# - Send an automatic message on each client listed in the comboBox -


i have client server program. once client connects server, client's ipaddress stored combobox. if want send message(using button) client, need select ipadress , send message. testing.

my main purpose want send same message(automatically) every client inside combobox once connect server. how can make server send message client? checks if new connects , automatically send same message.

this same message sent automatically.

public void sendtoclient()      {         try         {           for(int = 0; < mycombobox.items.count; i++)             {                 //string value = combobox1.getitemtext(combobox1.items[i]);                 senddata(openedfile.tostring());             }          }         catch (exception ex)         {             output.text += "error.....\n " + ex.stacktrace;          }     } 

and senddata() function

private void senddata(string data)         {             ipaddress ipep = ipaddress.parse(combobox1.selecteditem.tostring());             socket server = new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp);             ipendpoint ipept = new ipendpoint(ipep, hostport);             networkstream nstream = tcpclient.getstream();             asciiencoding asciidata = new asciiencoding();             byte[] buffer = asciidata.getbytes(data);             if (nstream.canwrite)             {                 nstream.write(buffer, 0, buffer.length);                 nstream.flush();             }         } 

i guess may following:

1) call senddata using different thread. achieve more performance , less delay (see below).

2) believe may detect add ip combobox make above call - it´s more efficient inspect whole ip´s in combobox, time. instance:

  '  @ point of module or top of form   dim listofips list(of string)    '  @ new connection event   listofips.add(ipnumber)   dim mythread thread = new thread(ctype(sub() senddata(ipnumber, mycustommessage), threadstart))             mythread.setapartmentstate(threading.apartmentstate.mta)             mythread.start() 

3) and, if need send message guys connected, may try like:

  each guy string in listofips             dim mythread thread = new thread(ctype(sub() senddata(guy, mycustommessage), threadstart))             mythread.isbackground = false             mythread.setapartmentstate(threading.apartmentstate.mta)             mythread.start()   next 

4) if see list(of t) help, find how locate , delete (or make blank string) ip whenever disconnects...


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -