I need to print on network Zebra printer. From some reasons, I cannot use winspool printing ( http://support.microsoft.com/kb/154078 ), I have to print print directly through sockets on IP and port. Here is my print method:
System.Net.Sockets.TcpClient zebraClient = new System.Net.Sockets.TcpClient();
try
{
zebraClient.SendTimeout = 5000;
zebraClient.Connect(IP, port);
}
catch (Exception ex)
{
Utils.ShowError(ex);
}
if (zebraClient.Connected)
{
NetworkStream nStream;
nStream = zebraClient.GetStream();
StreamWriter wStream;
using (nStream)
{
wStream = new StreamWriter(nStream);
using (wStream)
{
wStream.Write(content);
wStream.Flush();
}
}
zebraClient.Close();
}
Problem is, that from time to time "No connection could be created, because target computer actively refused it" exception occurs. I have no idea why is that happening (maybe full printer buffer - and if so, how can I check it in both languages?). So I ask if anybody have had this problem and how can I fix it?
I'm not sure if this would apply to you, but I ran into a similar problem using asp classic. I needed to print directly to a zebra printer without changing the default printer, so what I did as a solution was create a java executable that uses sockets to connect to the zebra printer. Once I had the java executable able to send a string of Zpl to the zebra printer through a stream on the open sockets I created a batch file to run my java executable. Since the executable needed a string from my asp page, I added a user input variable to the batch file. I placed these 2 files(the java jar and .bat file) on a shared drive and using ActiveX on the asp page, I was able to send raw bytes in the form of a string directly to my zebra printer. If you have any questions don't hesitate to ask. Below is a link that will help with implementing a way to socket print to a zebra printer through java. https://km.zebra.com/kb/index?page=content&id=SO7149&actp=RSS