Hi Guys,
I'm learning how winsock works before using it in an upcoming project. In this test project I am sending messages from the server to clients and clients to server. I've got everything working except there is a problem. The server can send data to the clients at the same time but only one client can send data to the server. Only the last client that connects can send data to the server. Please watch the video to get a clearer picture.
I don't know if the client is unable to send the data or if its the server's handling of that data which is causing the issue from what I've heard is that it couble be a bug and could be fixed in VB6 SP6 which I have. If anyone can help me it would be appreciated otherwise I'm going to have to do it in VB.NET .
Server Code:
Client Code:
Project:
Attachment 111607
I'm learning how winsock works before using it in an upcoming project. In this test project I am sending messages from the server to clients and clients to server. I've got everything working except there is a problem. The server can send data to the clients at the same time but only one client can send data to the server. Only the last client that connects can send data to the server. Please watch the video to get a clearer picture.
I don't know if the client is unable to send the data or if its the server's handling of that data which is causing the issue from what I've heard is that it couble be a bug and could be fixed in VB6 SP6 which I have. If anyone can help me it would be appreciated otherwise I'm going to have to do it in VB.NET .
Server Code:
Code:
Option Explicit
Dim iSockets As Integer
Dim sRequestID As String
Private Sub Command1_Click()
Dim A As Long
Dim B As Long
B = Winsock1.LBound + 1 'ignore socket(0) value
For A = B To Winsock1.UBound
If Winsock1(A).State = sckConnected Then
Winsock1(A).SendData "ctest": DoEvents
End If
Next A
End Sub
Private Sub Command2_Click()
Dim A As Long
Dim B As Long
B = Winsock1.LBound + 1 'ignore socket(0) value
For A = B To Winsock1.UBound
If Winsock1(A).State = sckConnected Then
Winsock1(A).SendData "ctest2": DoEvents
End If
Next A
End Sub
Private Sub Form_Load()
Winsock1(iSockets).LocalPort = 9584
Winsock1(iSockets).Listen
End Sub
Private Sub Winsock1_Close(Index As Integer)
Winsock1(Index).Close
Unload Winsock1(Index)
iSockets = iSockets - 1
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
sRequestID = requestID
iSockets = iSockets + 1
Load Winsock1(iSockets)
Winsock1(iSockets).LocalPort = 9584
Winsock1(iSockets).Accept requestID
End If
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim data As String
Winsock1(iSockets).GetData data
If data = "stest" Then
MsgBox "stest", vbInformation, "Server"
End If
If data = "stest2" Then
MsgBox "stest2", vbInformation, "Server"
End If
End Sub
Client Code:
Code:
Private Sub Command1_Click()
Winsock1.SendData "stest"
End Sub
Private Sub Command2_Click()
Winsock1.SendData "stest2"
End Sub
Private Sub Form_Load()
Winsock1.Close
Winsock1.Connect "192.168.235.128", 9584
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sData As String
Winsock1.GetData sData, vbString
If sData = "ctest" Then
MsgBox "ctest", vbInformation, "Client"
End If
If sData = "ctest2" Then
MsgBox "ctest2", vbInformation, "Client"
End If
End Sub
Attachment 111607