How do I send a string via tcpsocket


I am playing around with Web Apps and I want to communicate to an external server using tcpsockets. the server listens o a specific port.

I managed to establish a connection.

How do I send a simple String “Hello World” .

The server displays whatever is send in a text box.

Thanks for help

Look in /Applications/Xojo 2016 Release 3/Example Projects/Communication/Internet where there are two TCP communication example projects.

OK, I can send data now :slight_smile:

How do I receive data back?

Polling and reading data does not seems to work

dont poll
that will suck up a ton of CPU and block your app in other ways
tcp sockets can be event driven
you just need to handle the events they provide for dataavailable etc
and you can do this in many different ways

  1. in a GUI program drag an instance onto a layout & add the events
  2. use addhandler & removehandler to handle the events
  3. create a subclass that handles the events and then create instances of these in your application code

Thanks Norman,

I am trying out a Web Application.

So I can not use 1) I assume (no way to drag tcpsocket into the layout).

The server App I am trying to communicate with (a card game) is not build with Xojo (but pure basic) and uses TCP to talk to the client. There are clients for linux, windows and macOS already. We are trying to build a web interface / web client, so that users do not need to download a client software.

As said I am able to connect and send messages synchron to the server. Now I need to figure out how to asynchronous check if there is something new from the server.

Could this be done, using a timer for example to check each xx ms for new data?

yeah DONT use a timer
you’re almost guaranteed to miss data

the asynchronous way is to implement the events

if you cant drag one onto a layout you can still use the async method you just have to use #2 or #3 as I mentioned

#2 is pretty easy since all you really do is write a method that will be called when the event is raised by the framework (instead of adding the event to an instance on a window)
And then you can get data from the socket asynchronously

  • Drag a generic object onto your webpage
  • Set its super to TCPSocket

That’s it :slight_smile:


I have meanwhile a property in Session which is a TCPSocket. All users connected needs its own connection.

If I drag a generic Object on my page and make it a tcpsocket, can I link this one to the TCPSocket in the Session?

I don’t understand. What do you mean by “can I link this one to the TCPSocket in the Session?”

As a webcontrol part of a webpage, it is by definition part of the session.


Slightly shameless plug, but on the otherhand it is related to the OP’s question… I have a client socket code (it’s a little in flux, but it is 100% in the public domain) that you can take a look at… Any questions, feel free to message me on here (either in private or in this thread)