TPSocket, basic send function

HI, I am tinkering with TCPSocket, and I am not getting it, I used to do a lot of serial communication programming and just starting to use TCP. I am writing a little app to send a dozen or so commands to a piece of gear of ethernet, actually UDP. I have read through the TCPSocket stuff a couple times and I am still missing some things. I think I am not initializing the port correctly and I am not sure how to actually send the command. I do have the TCPSocket dropped on my app window. This what I cam up with parsing through some examples online. Here is my failing code snippet:

Dim IP as String
Dim PT as Integer
Dim theMessage As String

IP = TextField1.Text
PT = CDbl(TextField2.Text)

TCPSocket1.Address = IP //172.168.10.11 example
TCPSocket1.Port = PT // 11116 example
TCPSocket1.Connect

theMessage = (“spyder RSL 2 1”) // the message the receiver wants, in other programs, this message
//is ‘spyder\x00\x00\x00\x00RSL 2 1’ with the \x00 being for hex spaces
TCPSocket1.Write (theMessage)
TCPSocket1.Flush

You mention UDP and your code seems to be addressing a particular port on the remote device, so you should probably be using a UDPSocket instead of a TCPSocket.

\x00 would translate to chr(0) in Xojo, so try

“spyder”+chr(0)+chr(0)+chr(0)+chr(0)+“RSL 2 1”

More likely ChrB than Chr :slight_smile:

Ok back at it. So with UDPSocket, it does not use UDPSocket1.Address = IP //172.168.10.11 (like TCPSocket) but UDPSocket1.BroadcastAddress = …would this be there target IP address or something else like 172.168.10.255 I have tried both and I get this message “Cannot Assign a value to this property”.

Reading UDPSocket, it says I do not need to set an IP address, Just the port.

I figured it out, I needed to use Datagram.

Dim theMessage As String
Dim d as new Datagram

theMessage = (“spyder”+chr(0)+chr(0)+chr(0)+chr(0)+“RSC 10 1”)

d.Address = “172.168.10.11”
d.Port = 11116
d.Data = theMessage

UDPSocket1.Write d