Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock Getdata problem

Status
Not open for further replies.

jjjax0330

IS-IT--Management
Aug 15, 2005
76
US
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

 
I myself have noticed problems when trying to use the old VB6 winsock control with .NET (must be compatibility issues or something).

With the .NET framework however, MS provides a much richer way of communitcating across the network - via the Socket object (also more complicated).

Here are some links to examples of someone who created a Winsock replica for .NET - just choose your version:

.NET 1.1 (VB 2003) .NET 2.0 (VB 2005)
Hope that helps you out.
 
Thanks, got it to work with help from those links. Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top