system.net.sockets (HELP)

rmatthew

Centurion
Joined
Dec 30, 2002
Messages
115
Location
Texas
I am trying to use the following code and answer the connection request with a string. However; I never could get the send to work and I assume it is because the connected property is never set to true. Somebody please tell me what I am missing :)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

sckt.Blocking = True
sckt.Bind(endpoint)
sckt.Listen(10)
Dim callbk As New System.AsyncCallback(AddressOf callbak)
sckt.BeginAccept(callbk, 0)

End Sub

Private Sub callbak(ByVal ar As System.IAsyncResult)

Debug.Write("Connection Attempt")
Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes("Connection Accepted")

If sckt.Connected = True Then Debug.Write("connected")

End Sub

End Class
 
You haven't accepted the connection yet in your code. If you have made a call to BeginAccept previously, you will need to make a call to EndAccept to finish it off. If you consult the help for this method, there is usually an example of using it.
 
Back
Top