salve a tutti
avendo un programma, che lo avvio come finestra DOS e lui rimane in attesa di una chiamata TCP
il problema è che dopo varie chiamate, la RAM aumenta di continuo,e non riesco a determinare dove è il pezzo di codice che da il problema
faccio presente che le altre routine SUB che vengono chiamate sono totalmente escluse da bug in quanto le hoi usate per molto tempo in altri programmi,ovviamente penso che il problema sia qui in quanto è la prima volta che mi cimento in TCP
questo è il codice
codice:
Public Sub Main()
Dim TcpThread As Thread
Try
'Starting the TCP Listener thread.
TcpThread = New Thread(AddressOf StartListen)
TcpThread.Start()
Catch ex As Exception
Throw New Exception(ex.Message)
Console.WriteLine("Si è verificato un errore")
TcpThread.Abort()
End Try
End Sub
Public Sub StartListen()
' Must listen on correct port- must be same as port client wants to connect on.
Const portNumber As Integer = 8000
Dim tcpListener As New TcpListener(portNumber)
Dim clientData As String
Try
While (True)
tcpListener.Start()
Console.WriteLine("In attesa di una nuova richiesta...")
Dim tcpClient As TcpClient = tcpListener.AcceptTcpClient()
Console.WriteLine("Richiesta ricevuta.")
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim bytesToRead(tcpClient.ReceiveBufferSize) As Byte
Dim numBytesRead As Integer = networkStream.Read(bytesToRead, 0, CInt(tcpClient.ReceiveBufferSize))
clientData = Encoding.ASCII.GetString(bytesToRead, 0, numBytesRead)
Dim tipoOperazione As String = Left(clientData, 3)
Dim responseString As String
Select Case tipoOperazione
Case Is = "TUFF"
Console.WriteLine("operazione ripristino")
Call verifica(clientr)
responseString = Trasmissione & "?"
End Select
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(responseString, 0, responseString.Length)
networkStream.Write(sendBytes, 0, sendBytes.Length)
tcpClient.Close()
tcpListener.Stop()
End While
Catch ex As Exception
Console.WriteLine(ex.Message)
tcpListener.Stop()
End Try
End Sub
posto anche il codice che spedisce la stringa alla porta,forse si tratta qui del problema
codice:
Private Function SendDataBarcode(ByVal BarCode As String) As Boolean
Dim tcpClient As New TcpClient()
Try
tcpClient.Connect(Server, 8000)
Dim networkStream As NetworkStream = tcpClient.GetStream()
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("BAR@" & BarCode & "@" & Server)
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
Dim numBytesRead As Integer = networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
Dim returndata As String = Encoding.ASCII.GetString(bytes, 0, numBytesRead)
Dim datiServer() = Split(returndata, "@")
'Controllo il barcode.
If datiServer(0) <> "failed" Then
txtArticolo.Text = datiServer(6)
txtMarchio.Text = datiServer(1)
Return True
Else
Return False
End If
Catch ex As Exception
Return False
Finally
tcpClient.Close()
End Try
End Function