I am wondering if it can be programmed a little bit better so it will work faster.
Now i send for every item/feed a new request but i want to sent more then 1 item to the datastream in 1 request. I have tried a few possibilities but without any success.
Thank you.
Now my code is:
'all the items have the same connection, apiKey and feedId
'Sending the items every 30 seconds
Item1 = "Volt,23" Item2 = "Ampere,3" Item3 = "Direction,34.2" Do While True Using connection As Socket = Connect(URi, 5000) SendRequest(connection, apiKey, feedId, Item1) SendRequest(connection, apiKey, feedId, Item2) SendRequest(connection, apiKey, feedId, Item3) End Using 'do other things for 30 seconds and read the new data in the items loop Private Function Connect(ByVal host As String, ByVal timeout As Integer) As Socket ' look up host's domain name to find IP address(es) Dim hostEntry As IPHostEntry = Dns.GetHostEntry(host) ' extract a returned address Dim hostAddress As IPAddress = hostEntry.AddressList(0) Dim remoteEndPoint As New IPEndPoint(hostAddress, 80) Dim connection = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) connection.Connect(remoteEndPoint) connection.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, True) connection.SendTimeout = timeout Return connection End Function Private Sub SendRequest(ByVal s As Socket, ByVal apiKey As String, ByVal feedId As String, ByVal content As String) Dim contentBuffer As Byte() = Encoding.UTF8.GetBytes(content) Dim CRLF As String = Constants.vbCr & Constants.vbLf Dim requestLine = "PUT /v2/feeds/" & feedId & ".csv HTTP/1.1" & CRLF Dim requestLineBuffer As Byte() = Encoding.UTF8.GetBytes(requestLine) Dim headers = "Host: api.pachube.com" & CRLF & "X-PachubeApiKey: " & apiKey & CRLF & "Content-Type: text/csv" & CRLF & "Content-Length: " & contentBuffer.Length & CRLF & CRLF Dim headersBuffer As Byte() = Encoding.UTF8.GetBytes(headers) s.Send(requestLineBuffer) s.Send(headersBuffer) s.Send(contentBuffer) End Sub