I am probably doing it wrong since its obviously not working..
But here is my server:
And my client:
Sooo when I click the "Login" button on the client, it will connect to 127.0.0.1 on port 7667
so I would like it to send data to the server saying "^connected"
and when that server recieves "^connected" I would like it to say in the richtextbox "A player connected" or something..
but everytime I click the login button while listening the server the label1.text actually turns to "Connected!"
but doesn't send any data to the server... :/
How can I make this work please?
But here is my server:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Winsock1.RemotePort = 7667
Winsock1.Listen()
RichTextBox1.AppendText("Server listened on port " + Convert.ToString(Winsock1.RemotePort) + vbCrLf)
Button1.Enabled = False
Button2.Enabled = True
Catch ex As Exception
MsgBox("Error trying to listen!", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Winsock1.Close()
Button1.Enabled = True
Button2.Enabled = False
RichTextBox1.AppendText("[WARNING] Server's socket was shutdown." + vbCrLf)
End Sub
Private Sub Winsock1_DataArrival(ByVal sender As Object, ByVal e As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles Winsock1.DataArrival
Dim data As String = ""
Dim opt() As String
opt = Split(data, "||")
Winsock1.GetData(data)
Select Case opt(0)
Case "^connected"
RichTextBox1.AppendText("Player connected to the server." + vbCrLf)
Case "^message"
RichTextBox1.AppendText("Player talk: " + opt(1) + vbCrLf)
End Select
End Sub
End Class
And my client:
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Winsock1.Connect("127.0.0.1", "7667")
Label1.Text = "Connected!"
Catch ex As Exception
Label1.Text = ""
MsgBox("Server is currently offline!", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Winsock1.Close()
Label1.Text = "."
Catch ex As Exception
End Try
End Sub
Private Sub Winsock1_ConnectEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Winsock1.ConnectEvent
Label1.Text = "Connected!"
Winsock1.SendData("^connected")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Winsock1.SendData("^message ||" + TextBox3.Text)
End Sub
End Class
Sooo when I click the "Login" button on the client, it will connect to 127.0.0.1 on port 7667
so I would like it to send data to the server saying "^connected"
and when that server recieves "^connected" I would like it to say in the richtextbox "A player connected" or something..
but everytime I click the login button while listening the server the label1.text actually turns to "Connected!"
but doesn't send any data to the server... :/
How can I make this work please?