COM objects from within TCP Client

siv_83

New member
Joined
Feb 17, 2009
Messages
1
Programming Experience
3-5
Hi All,

I hope I am using the correct room to post this. This issue has been killing me to the point that I think I am losing some hair from it!

Basically, I a have a server that waits for commands, which can either be:

Scan or OCR

Most of the time, the commands it receives are a sequential scan and OCR which basically tell the server to invoke the Scan module (takes a partial screenshot of the screen and saves it as Tiff) and then OCR it using the MODI.Document COM object.

The scan and OCR commands are received once every second (it takes around 500ms to process both) and for each command, the server sends an ACK back.

This works for several scans and OCRs but then it crashes saying that a COMexeption occurred with message RPC_E_Serverfault. The error is thrown at the miDoc.OCR() part.

Any suggestions?

The code for the server:

Imports System.Text
Imports System.Net.Sockets
Imports System.Net

Public Class Server

Dim Data As Integer
Dim Message As String
Dim TCPL As TcpListener
Dim TCPC As New TcpClient
Dim BufferSize(TCPC.ReceiveBufferSize - 1) As Byte
Dim sendData() As Byte
Dim miDoc As MODI.Document
ReadOnly ACK As String = "ACK "
ReadOnly EOF As String = "<EOF>"
Dim wc As WindowCapture = New WindowCapture
Public saveLocation As String


Sub Server_Load()

Try
TCPL = New TcpListener(22000)
TCPL.Start()
TCPC.NoDelay = True
System.Console.WriteLine("Waiting for connection...")
TCPL.BeginAcceptTcpClient(AddressOf OnConnect, Nothing)
Catch ex As Exception
System.Console.WriteLine("Error: " & ex.Message)
End Try
End Sub

Private Sub OnConnect(ByVal AR As IAsyncResult)

TCPC = TCPL.EndAcceptTcpClient(AR)
System.Console.WriteLine("Connected")
System.Console.WriteLine("Waiting for client command....")
TCPC.GetStream.BeginRead(BufferSize, 0, BufferSize.Length, AddressOf OnRead, _
Nothing)
End Sub

Private Sub OnRead(ByVal AR As IAsyncResult)

Data = TCPC.GetStream.EndRead(AR)
Message = Encoding.ASCII.GetString(BufferSize, 0, Data)
ProcessCommand(Message)
System.Console.WriteLine("Waiting for client command....")
TCPC.GetStream.BeginRead(BufferSize, 0, BufferSize.Length, AddressOf OnRead, _
Nothing)

End Sub

Private Sub OnWrite(ByVal AR As IAsyncResult)
TCPC.GetStream.EndWrite(AR)
TCPC.GetStream.BeginRead(BufferSize, 0, BufferSize.Length, AddressOf OnRead, _
Nothing)
End Sub

Private Sub OnQuit(ByVal AR As IAsyncResult)

TCPC.GetStream.EndWrite(AR)

While (TCPC.Connected)
Threading.Thread.Sleep(1000)
End While

TCPC.Close()
TCPL.Stop()
miDoc = Nothing
Console.WriteLine("Server down......" & ControlChars.NewLine & "Type server to restart or press enter to exit...")

End Sub

Private Sub ProcessCommand(ByVal m As String)

Select Case m.Split("$")(0)

Case "Scan"

Console.WriteLine("Request for Scaning part of the desktop received...")
Module1.scanSmall(wc, m.Split("$")(1), Integer.Parse(m.Split("$")(2)), Integer.Parse(m.Split("$")(3)), Integer.Parse(m.Split("$")(4)), Integer.Parse(m.Split("$")(5))) 'coordinates to scan
sendData = Encoding.ASCII.GetBytes("Scanning " + m.Split("$")(1) + " [OK]" + EOF) ' ack string
TCPC.GetStream.BeginWrite(sendData, 0, sendData.Length, AddressOf OnWrite, Nothing)
Console.WriteLine("Scanning [OK]")

Case "ocr"

Console.WriteLine("Request for OCR received...")
miDoc = New MODI.Document()
miDoc.Create(saveLocation)
miDoc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, False, False)
sendData = Encoding.ASCII.GetBytes(miDoc.Images.Item(0).Layout.Text() + EOF) 'Comex is caught here or the line below. This runs fine for between 50-100 consequitive commands but then breaks
TCPC.GetStream.BeginWrite(sendData, 0, sendData.Length, AddressOf OnWrite, Nothing)
miDoc.Close(False)
miDoc = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
miDoc = New MODI.Document
Console.WriteLine("OCR [OK]")

Case "QUIT"

Console.WriteLine("Request for shutdown received...")
sendData = Encoding.ASCII.GetBytes(ACK + m + EOF)
TCPC.GetStream.BeginWrite(sendData, 0, sendData.Length, AddressOf OnQuit, Nothing)

Case Else

System.Console.ReadLine()


End Select

End Sub

End Class
 

jewfish1010

New member
Joined
Feb 23, 2009
Messages
1
Programming Experience
3-5
I cannot offer any direct assistance with this ocr com dll, however I can offer some ideas.

I've worked with the domino com interface with webservices and I can tell you that drove me bonkers for ages, until I found my own IIS server and plonked the service on a machine where I was able to set IIS 6 into iis 5 isolation mode.

Some ideas,
* Com object may only like to be a single instance
* Com object may prefer STA threads

If your remoting object is hosted in IIS 6, try the 5 isolation mode.
Rob.
 
Top Bottom