Note that there are some explanatory texts on larger screens.

plurals
  1. POAsync Socket Sending Problem after Control.Invoke method
    primarykey
    data
    text
    <p>I have got a Client/Server Application that using Asynchronous Socket.I have got a method for sending data to client from server side and client got a method for handle this data and control client's forms control.</p> <p>Because of using Async socket I need to use <code>Control.Invoke</code> method for access Main Thread. But i got a problem--after I use <code>Control.Invoke</code> it starts data sending problem to Server Side. Its get into socketClient.Send(byteArray); but not sending data to server. If i dont use Invoke.Method i cant able to control client side forms controls :( </p> <p>What I have to do?</p> <p>Ok I found my problem but its not about Control.Invoke its a socket data transmission issue.But i could not solve it.When i use repeadetly socketClient.Send() method only first socketclient.Send() is working other not. Here is my codes ;</p> <p>// When client is connected this method is working.</p> <pre><code>void baglantiSaglandi(IAsyncResult sonuc){ try { Aday gelenAday = new Aday(); bagliAdayListesi.Add(gelenAday); gelenAday.adaySoket = serverSocket.EndAccept(sonuc); TamponTemizle(); // Client'in gönderdiği veriyi kabul edip, boyutunu gelendataBoyutu isimli değişkene atadık. int gelendataBoyutu = gelenAday.adaySoket.Receive(tampon); // Client'in ip adresini ipadresi property imize ekledik. gelenAday.ipAdresi = Mesaj(StringeDonustur(tampon, gelendataBoyutu)); lstKullanicilar.Items.Add(gelenAday.ipAdresi); grpYonetim.Enabled = true; lblUyari.Visible = false; serverSocket.BeginAccept(new AsyncCallback(baglantiSaglandi), null); TamponTemizle(); gelenAday.adaySoket.BeginReceive(tampon, 0, tampon.Length, SocketFlags.None, new AsyncCallback(mesajGeldi), gelenAday); } catch (SocketException ex) { MessageBox.Show(ex.Message); } } </code></pre> <p>//When Clients sent message to server this code block is working.</p> <pre><code>void mesajGeldi(IAsyncResult sonuc){ Aday stateAday = sonuc.AsyncState as Aday; try { int gelenDataBoyutu = stateAday.adaySoket.EndReceive(sonuc); MesajKontrol(StringeDonustur(tampon, gelenDataBoyutu), stateAday.ipAdresi); } catch (SocketException ex) { if (ex.SocketErrorCode == SocketError.ConnectionReset) { foreach (Aday cikanAday in bagliAdayListesi) { if (cikanAday.ipAdresi == stateAday.ipAdresi) { cikanAday.adaySoket.Close(); bagliAdayListesi.Remove(cikanAday); // lstKullanicilar.Items.Remove(cikanAday.ipAdresi); if (lstKullanicilar.Items.Count &lt;= 0) { grpYonetim.Enabled = false; lblUyari.Visible = true; } break; } } } } } </code></pre> <p>//this method is handling Client's messages </p> <pre><code>void MesajKontrol(string mesaj, string aday) { if (mesaj.Length &lt; 1) return; switch (mesaj.Substring(0, 3)) { case "/s/": string[] yanlisDogru = Mesaj(mesaj).Split(','); foreach (Aday cikanAday in bagliAdayListesi) { if (cikanAday.ipAdresi == aday) { lstKullanicilar.Items[bagliAdayListesi.IndexOf(cikanAday)].SubItems.Add(yanlisDogru[1]); lstKullanicilar.Items[bagliAdayListesi.IndexOf(cikanAday)].SubItems.Add(yanlisDogru[0]); } } break; case "/q/": foreach (Aday cikanAday in bagliAdayListesi) { if (cikanAday.ipAdresi == aday) { cikanAday.adaySoket.Close(); bagliAdayListesi.Remove(cikanAday); //lstKullanicilar.Items.Remove(cikanAday.ipAdresi); if (lstKullanicilar.Items.Count &lt;= 0) { grpYonetim.Enabled = false; lblUyari.Visible = true; } break; } } break; case "/b/": foreach (Aday cikanAday in bagliAdayListesi) { if (cikanAday.ipAdresi == aday) { lstKullanicilar.Items[bagliAdayListesi.IndexOf(cikanAday)].SubItems.Add(Mesaj(mesaj)); lstKullanicilar.Items[bagliAdayListesi.IndexOf(cikanAday)].SubItems.Add("0"); lstKullanicilar.Items[bagliAdayListesi.IndexOf(cikanAday)].SubItems.Add("0"); } } break; default: break; } } </code></pre> <p>//This code block is working from client side and the problems begin here there are 2 Send method working but only the first is executed at the server. </p> <pre><code>private void btnYazdir_Click(object sender, EventArgs e) { clientSocket.Send(ByteArrayeDonustur("/s/" + yanlis.ToString() + "," + dogru.ToString())); clientSocket.Send(ByteArrayeDonustur("/b/" + txtAdSoyad.Text)); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload