user287848 user287848 - 7 months ago 25
Vb.net Question

XMLHttpRequest stops sending after 6 times

chrome.browserAction.onClicked.addListener(function (tab) {
var httpReq = new XMLHttpRequest();
httpReq.addEventListener("error", function() { console.error(httpReq.status + " " + httpReq.statusCode); })
var dotNetUrl = "http://localhost:60005/";
httpReq.open("POST", dotNetUrl)
httpReq.send("HELLO");
})


After 6 clicks, requests stop sending. If I reload my extension or the server, I can send 6 more. My VB.NET application is receiving on the other end.

Public Async Sub CallListener()
Await Threading.Tasks.Task.Run(Sub() Listener())
End Sub

Public Sub Listener()
Try
While (True)
Dim t = hListener.GetContextAsync()
Dim context As HttpListenerContext = t.Result()
Dim request As HttpListenerRequest = context.Request()

Dim stream As IO.Stream = request.InputStream
Dim reader As IO.StreamReader = New IO.StreamReader(stream)
Dim streamRTE As String = reader.ReadToEnd()

stream.Close()
reader.Close()

RaiseEvent DataReceived(streamRTE)
End While
Catch ex As Exception
End Try
End Sub


I built a test VB.NET client to see if it was my server, but it wasn't. The client could send as many as it wanted, and the server received it. Perhaps there's some incompatibility? I simply want my Google Chrome extension to send data to my .NET application. My extension shouldn't need to receive anything.

Answer

It's caused by the lack of response from server.

The VB code

Dim response As HttpListenerResponse = context.Response()
Dim responseString As String = ""
Dim b As Byte() = System.Text.Encoding.UTF8.GetBytes(responseString)
Dim outputStream As IO.Stream = response.OutputStream
outputStream.Write(b, 0, b.Length)
outputStream.Close()

Now the browser should be able to make more requests, as there will be no pending ones, because server responses.