New to winsock but trying to get my feet wet for an upcoming project. Running vb.net and found some sample code on the web but most seem to be for old versions because most have to go through the update procedure when opening in visual studio.net 2003. The problem that I seem to be having with all of them is that it doesn’t seem to be able to get the data. The example below allows the connection because I see the client IP come up on the server when it does connect. I added the msgboxes just to see if it actually getting anywhere in the dataarrival event and the first msgbox does come up but not the one after the getdata statement. No error or anything, it just seems to do nothing. I have tried a few different samples that I found out there but seem to have same problem with all.
Client
Private Sub cmdSend_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Winsock1.SendData(Text3.Text & vbCrLf)
MsgBox(Text3.Text) ‘This does popup and show correct data
End Sub
Private Sub cmdConnect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
With Winsock1
.Close()
.RemoteHost = Text1.Text
.RemotePort = CInt(Text2.Text)
.Connect()
End With
End Sub
Server
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
With Winsock1
.Close()
.LocalPort = 5050
.Listen()
End With
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles Winsock1.ConnectionRequest
Winsock1.Close()
Winsock1.Accept(eventArgs.requestID)
Text1.Text = Winsock1.RemoteHostIP ‘This does work and loads field
End Sub
Private Sub Winsock1_DataArrival(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles Winsock1.DataArrival
Dim thedata As String
Static Buffer As String
Dim Temp As String, Temps() As String
MsgBox("1") ‘ This does popup
Winsock1.GetData(Temp)
MsgBox("2") ‘ Never gets here but no error
Temp = Buffer & Temp
Temps = Split(Temp, vbCrLf)
Buffer = Temps(UBound(Temps))
Text2.Text = thedata
End Sub
Client
Private Sub cmdSend_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Winsock1.SendData(Text3.Text & vbCrLf)
MsgBox(Text3.Text) ‘This does popup and show correct data
End Sub
Private Sub cmdConnect_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
With Winsock1
.Close()
.RemoteHost = Text1.Text
.RemotePort = CInt(Text2.Text)
.Connect()
End With
End Sub
Server
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
With Winsock1
.Close()
.LocalPort = 5050
.Listen()
End With
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent) Handles Winsock1.ConnectionRequest
Winsock1.Close()
Winsock1.Accept(eventArgs.requestID)
Text1.Text = Winsock1.RemoteHostIP ‘This does work and loads field
End Sub
Private Sub Winsock1_DataArrival(ByVal eventSender As System.Object, ByVal eventArgs As AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent) Handles Winsock1.DataArrival
Dim thedata As String
Static Buffer As String
Dim Temp As String, Temps() As String
MsgBox("1") ‘ This does popup
Winsock1.GetData(Temp)
MsgBox("2") ‘ Never gets here but no error
Temp = Buffer & Temp
Temps = Split(Temp, vbCrLf)
Buffer = Temps(UBound(Temps))
Text2.Text = thedata
End Sub