Ik probeer een simpele chat server te maken waar een client naartoe kan verbinden (gewoon 1 client per server
) het connecten lukt wel maar nu wil ik een sub laten uitvoeren op de server als een client connect en dat lukt me niet helemaal 
Server Code
Client Code
Kan iemand mij vertellen wat ik fout doe?
Server Code
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| Imports System.Net
Imports System.Net.Sockets
Public Class frmChat
Inherits System.Windows.Forms.Form
Private objTpcLis As TcpListener
Public Event Connected(ByVal sender As Object)
Private Sub OnConnect(ByVal sender As System.Object)
MsgBox("YEA!")
End Sub
Private Sub frmChat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
objTpcLis = New TcpListener(System.Net.IPAddress.Any, 7000)
objTpcLis.Start()
AddHandler Connected, AddressOf OnConnect
Catch ex As Exception
MsgBox("Error")
End Try
End Sub
End Class |
Client Code
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Public Class frmChat
Inherits System.Windows.Forms.Form
Private objTpcClient As TcpClient
Private Sub DisplayText(ByVal strText As String)
txtMessages.AppendText(strText & vbCrLf)
End Sub
Private Sub SendText(ByVal strText As String)
Dim objSW As New StreamWriter(objTpcClient.GetStream)
objSW.Write(strText)
objSW.Flush()
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
Dim blnError As Boolean = False
Try
objTpcClient = New TcpClient(txtIP.Text, txtPort.Text)
Catch ex As Exception
blnError = True
DisplayText("Connection failed: " & ex.Message)
Finally
If Not blnError Then
DisplayText("Connected to: " & txtIP.Text & ":" & txtPort.Text)
End If
End Try
End Sub
Private Sub btnSendMsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendMsg.Click
DisplayText(txtNewMsg.Text)
SendText(txtNewMsg.Text)
txtNewMsg.Text = ""
End Sub
End Class |
Kan iemand mij vertellen wat ik fout doe?