Send command "string" over tcp/ip

stevedee
Posts: 83
Joined: Monday 20th March 2017 6:06pm

Re: Send command "string" over tcp/ip

Post by stevedee » Sunday 25th February 2018 10:10am

jornmo wrote:
Sunday 25th February 2018 8:17am
...Its the javascript on this site that takes care of the syntax highlighting...
Thanks Jornmo, don't waste any time on it, I was just curious. I couldn't see any non-printing characters or anything unusual that might cause it within the text block.

agili
Posts: 6
Joined: Wednesday 21st February 2018 8:22pm

Re: Send command "string" over tcp/ip

Post by agili » Sunday 25th February 2018 1:51pm

Cogier: I compiled the code with no errors but got time out and no reaction from print server, I started the app and started terminal , used the command : netstat -at , my specified port did not appear at all no communication. By the way if I use the app I created in windows with VB (run with wine on linux mint 18) I get response with the print server and can send commands successfully. I am stuck.

User avatar
cogier
Site Admin
Posts: 192
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Send command "string" over tcp/ip

Post by cogier » Monday 26th February 2018 12:21pm

Can you post the VB code you are using with Wine that works please.

agili
Posts: 6
Joined: Wednesday 21st February 2018 8:22pm

Re: Send command "string" over tcp/ip

Post by agili » Tuesday 27th February 2018 10:05pm

Cogier: This code is writen in visual Basic 2017 on windows 10 and perfectly works:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim ipAddress As String = "192.168.100.237"
Dim port As Integer = 9100
Dim ZPLString As String =
"^XA" &
"~JA" &
"^XZ"
Try
'Open Connection
Dim client As New System.Net.Sockets.TcpClient
client.Connect(ipAddress, port)
'Write ZPL String to Connection
Dim writer As New System.IO.StreamWriter(client.GetStream())
writer.Write(ZPLString)
writer.Flush()
'Close Connection
writer.Close()
client.Close()
Catch ex As Exception
End Try

End Sub

stevedee
Posts: 83
Joined: Monday 20th March 2017 6:06pm

Re: Send command "string" over tcp/ip

Post by stevedee » Wednesday 28th February 2018 8:42am

agili wrote:
Sunday 25th February 2018 1:51pm
...I started the app and started terminal , used the command : netstat -at , my specified port did not appear at all no communication...
Please put a breakpoint at the line:-
If ClientSocket.Status > Net.Inactive Then
...and then run the code in the Gambas IDE.

If the code does not stop at the breakpoint, then there is an error and you should see info in the lower window in the IDE.

If the code stops at the breakpoint, use netstat -at in a terminal and see if the port is open.

The example I gave you is very basic. In my blog post is does say that you should add error detection. Also, in my example above, the string commands may not be correct, so the socket may just be opening and then closing (as expected), so you wont see it on netstat unless you pause the code.

The command string may need to be changed (e.g. to include CR + LF). But the first step is to ensure the socket is working as expected.

EDIT: you don't need to compile the code each time, just click the Run button in the IDE to test your code.

User avatar
Matthew-Collins
Posts: 4
Joined: Wednesday 21st September 2016 7:59pm
Location: Guernsey, Channel Islands

Re: Send command "string" over tcp/ip

Post by Matthew-Collins » Thursday 01st March 2018 3:37pm

Hi Agili,

Myself and Charlie have done some testing for you, the issue is the iptables firewall on linux mint.

Try these steps:
1) Turn Off ufw firewall > Status: Off (can be done from gufw "Firewall Configuration")

In Terminal:
2) sudo iptables --flush
3) sudo iptables -X
4) sudo iptables --list (3 sections should be shown all saying: Accept)

5) Restart PC

For more information about the iptables and ufw firewall, see this link:
https://help.ubuntu.com/community/IptablesHowTo
Cheers
Matt

Post Reply