addicktz
asked on
Need Faster Socket.BeginRecieve and Socket.Send
My Question is, is there any way to make that send faster? Should I be using something different than a Socket if I want to go faster? by faster I mean, maximizing my internet connection....and the same with the BeginRecieve, can I somehow have the send and the recieve on seperate threads? would that increase download and upload rates?
Ok my Socket.Send is this
Public Sub sendall(ByVal low As String, ByVal high As String, ByVal s As Socket)
nlow = low
dohed = True
Dim g As String : Dim h() As Byte
RaiseEvent Err(Date.Now)
Do Until nlowcnt = 500
g = "HEAD " & nlow & vbCrLf
h = StringToBytes(g)
s.Send(h, h.Length, 0)
nlow += 1
nlowcnt += 1
Loop
RaiseEvent Err(Date.Now)
End Sub
My BeginRecieve is this
Private Sub sockDataArrival(ByVal ar As IAsyncResult)
Dim state As StateObject = CType(ar.AsyncState, StateObject)
Dim client As Socket = state.workSocket
Dim bytesRead As Integer
Try
bytesRead = client.EndReceive(ar)
Catch
Exit Sub
End Try
Try
Dim Data() As Byte = state.buffer
If bytesRead = 0 Then
client.Shutdown(SocketShut down.Both)
client.Close()
RaiseEvent Err("ON DISCONNECT")
Exit Sub
End If
ReDim state.buffer(32767)
client.BeginReceive(state. buffer, 0, state.BufferSize, SocketFlags.Peek, AddressOf sockDataArrival, state)
ondataarrival(Data, bytesRead, client)
Catch ex As Exception
RaiseEvent Err(ex.ToString)
Exit Sub
End Try
End Sub
Ok my Socket.Send is this
Public Sub sendall(ByVal low As String, ByVal high As String, ByVal s As Socket)
nlow = low
dohed = True
Dim g As String : Dim h() As Byte
RaiseEvent Err(Date.Now)
Do Until nlowcnt = 500
g = "HEAD " & nlow & vbCrLf
h = StringToBytes(g)
s.Send(h, h.Length, 0)
nlow += 1
nlowcnt += 1
Loop
RaiseEvent Err(Date.Now)
End Sub
My BeginRecieve is this
Private Sub sockDataArrival(ByVal ar As IAsyncResult)
Dim state As StateObject = CType(ar.AsyncState, StateObject)
Dim client As Socket = state.workSocket
Dim bytesRead As Integer
Try
bytesRead = client.EndReceive(ar)
Catch
Exit Sub
End Try
Try
Dim Data() As Byte = state.buffer
If bytesRead = 0 Then
client.Shutdown(SocketShut
client.Close()
RaiseEvent Err("ON DISCONNECT")
Exit Sub
End If
ReDim state.buffer(32767)
client.BeginReceive(state.
ondataarrival(Data, bytesRead, client)
Catch ex As Exception
RaiseEvent Err(ex.ToString)
Exit Sub
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.