I have a server used to get info from SAPGUI. Everything works fine for a first request but nothing after that. The first iteration waits for a socket event. Once the socket is read for the first time it just loops without reading the receive buffer. I am assuming I need to reset the listener but am having trouble doing so.
'first iteration it works as expected but readbyte is always 0 after that even though it loops through fine. 'what I don't get is that the first iteration it waits for data to come down the socket, but after that it just loops 'and doesn't retreive anything.
I tried adding setting infinitecounter = 2 before the next statement and adding an if statement to reset the listener but failed.Code:Dim listenerSocket As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim ipend As IPEndPoint = New IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888) listenerSocket.Bind(ipend) listenerSocket.Listen(0) Dim clientSocket As Socket = listenerSocket.Accept() Dim Buffer As Byte() = New Byte(clientSocket.SendBufferSize - 1) {} Dim readByte, sendByte As Integer Dim Sbuffer As Byte() = System.Text.Encoding.ASCII.GetBytes("Some form of SAP response!") Dim clientError As System.Net.Sockets.SocketError Console.WriteLine("Waiting for connection : ") For infinitecounter = 1 To 3 infinitecounter = 1 readByte = clientSocket.Receive(Buffer) While (True) If readByte > 0 Then Dim rData As Byte() = New Byte(readByte - 1) {} Array.Copy(Buffer, rData, readByte) SAPrq = System.Text.Encoding.UTF8.GetString(rData) SAPpar = Left(SAPrq, 1) SAPpar1 = InStr(SAPrq, "%") If SAPpar = 1 Then SAPnwk = Mid(SAPrq, 3) xy = Getbam(SAPnwk)' this is a function that talks to SAP and it works on first loop End If End While Next`
I am not that good at VB.NET so even if there may be related posts , I am too inexperienced to hack them to fit my needs.
I've been working on a solution for a while and can't find a solution on my own.
Pete




Reply With Quote
