I
id10t error
Hello,
I am trying to write soem code that will send data to an Oneil
printer
over our network. I know the printer works and is setup correctly
because I can print to it from there software. In my program i am
getting this error.
System.IO.IOException was unhandled
Message="Unable to read data from the transport connection: An
existing connection was forcibly closed by the remote host."
I will post my code below. Any help would be great.
Imports System.Net.Sockets
Imports System.Text
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim tcpClient As New System.Net.Sockets.TcpClient()
'tcpClient.Connect(hostname, port)
tcpClient.Connect("10.0.9.106", 515)
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(" EZ{PRINT,STOP35020,35:ZP08A|003|")
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))' ---> this is the line giving me
the error
' Output the data received from the host to the console.
Dim returndata As String =
Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Host returned: " + returndata))
Else
If Not networkStream.CanRead Then
Console.WriteLine("cannot not write data to this
stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
Console.WriteLine("cannot read data from this
stream")
tcpClient.Close()
End If
End If
End If
' pause so user can view the console output
Console.ReadLine()
End Sub
End Class
I am trying to write soem code that will send data to an Oneil
printer
over our network. I know the printer works and is setup correctly
because I can print to it from there software. In my program i am
getting this error.
System.IO.IOException was unhandled
Message="Unable to read data from the transport connection: An
existing connection was forcibly closed by the remote host."
I will post my code below. Any help would be great.
Imports System.Net.Sockets
Imports System.Text
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim tcpClient As New System.Net.Sockets.TcpClient()
'tcpClient.Connect(hostname, port)
tcpClient.Connect("10.0.9.106", 515)
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(" EZ{PRINT,STOP35020,35:ZP08A|003|")
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))' ---> this is the line giving me
the error
' Output the data received from the host to the console.
Dim returndata As String =
Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Host returned: " + returndata))
Else
If Not networkStream.CanRead Then
Console.WriteLine("cannot not write data to this
stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
Console.WriteLine("cannot read data from this
stream")
tcpClient.Close()
End If
End If
End If
' pause so user can view the console output
Console.ReadLine()
End Sub
End Class