I've written an Asynchronous Socket client, which is working ok. I'm still on the learning curve from VB6 to .NET and there's one or two things I'm not clear about.
Part of the code requires sending the user's input to the Socket, using the BeginSend method. This requires the data to be sent as a Byte Array. Currently I'm doing this:
which seems to be a bit 'clunky' and 'vb6ish'. I feel as though I ought to be able to use 'MessageToSend.ToCharArray' and somehow coerce the result into a byte array.Code:If txtToSend.Text <> vbNullString Then MessageToSend = txtToSend.Text & vbNewLine Dim bytSend(MessageToSend.Length - 1) As Byte For i = 0 To MessageToSend.Length - 1 bytSend(i) = Asc(MessageToSend.Substring(i, 1)) Next Client.Client.BeginSend(bytSend, 0, MessageToSend.Length, 0, AddressOf SendCallback, Client) End If
Or is there something quite fundamental I'm missing?




Reply With Quote