Salut !
Je m'inspire d'un serveur de tchat CONSOLE et j'aimerais le refaire en windows form.
Mais j'ai un probleme, arrivé a mon "AcceptTcpClient" (Ligne 33) mon appli ce bloque complétement, je ne peux plus rien faire...
Voici le code au complet :
Code :
- Imports System.Net.Sockets
- Imports System.IO
- Imports System.Net
- Public Class Form1
- Dim Etat As Boolean
- Private Serveur As TcpListener
- Private Client As New TcpClient
- Private IPendpoint As IPEndPoint = New IPEndPoint(IPAddress.Any, 10)
- Private ListConnec As New List(Of Connection)
- Private Structure Connection
- Dim Stream As NetworkStream
- Dim Writer As StreamWriter
- Dim Reader As StreamReader
- Dim Pseudo As String
- End Structure
- Private Sub BtnConnect_Click(sender As Object, e As EventArgs) Handles BtnConnect.Click
- TxtEtat.Text = "En ligne"
- Serveur = New TcpListener(IPendpoint)
- Serveur.Start()
- While True
- Client = Serveur.AcceptTcpClient
- Dim c As New Connection
- c.Stream = Client.GetStream
- c.Reader = New StreamReader(c.Stream)
- c.Writer = New StreamWriter(c.Stream)
- c.Pseudo = c.Reader.ReadLine
- ListConnec.Add(c)
- 'ListCo.Items.Add(c.Pseudo)
- Dim t As New Threading.Thread(AddressOf ListenToConnection)
- t.Start(c)
- End While
- End Sub
- Private Sub ListenToConnection(ByVal con As Connection)
- Do
- Try
- Dim tmp As String = con.Reader.ReadLine
- ListHistorique.Items.Add(con.Pseudo & " : " & tmp)
- For Each c As Connection In ListConnec
- Try
- c.Writer.WriteLine(con.Pseudo & " : " & tmp)
- c.Writer.Flush()
- Catch
- End Try
- Next
- Catch
- ListConnec.Remove(con)
- ListCo.Items.Remove(con.Pseudo)
- Exit Do
- End Try
- Loop
- End Sub
- Private Sub BtnDeconnect_Click(sender As Object, e As EventArgs) Handles BtnDeconnect.Click
- Etat = False
- End Sub
- End Class
|
Si quelqu'un a une idée Je need
Message édité par naografix le 11-09-2013 à 18:17:53