TCP client

I want to make a very simple iOS TCP client to connect to a linux server api, which uses tcp sockets, and wonder is there already something I can use that RO have done, or is CFStreamCreatePairWithSocketToHost the right thing to use? It’s JSON API, so I can see how to use the Elements RTL parts for the response.

I’d suggest using Internet Pack (https://github.com/remobjects/InternetPack) if you want to be cross-platform (and/or want a better abstraction that the CF socket APIs provide).

I believe Diego is currently doping work to improve/extend the socket support further, partly in preparation for its use in Gold; I’m not sure if those changes affect Cocoa as well, or just Island, for now. In either case, IOP should be usable in its current state.

Thanks, I’ve got it in my project fine, but could use an example of how to use the client. Is Diego a user on here, so I could ask him perhaps?

Hi Jeremy,
to use basic tcp connection using internetpack you can use:
uses
RemObjects.InternetPack;

  var lSocket := new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
  lSocket.Connect('10.6.25.148', 15000); // target IP and target port
  var lBuf := new Byte[1024];      
  lSocket.Receive(lBuf, 128); // use to receive data from target
  lSocket.Send(lBuf); // to send data

this is the basic functionality, let me know what specific things you need

Diego,

don’t we have higher-level Client and Server abstraction classes for this (as old .NET-only IP did)?

yes, same classes, like TcpClient (sorry, exposed earlier most basic class):

  var lClient := new RemObjects.InternetPack.TcpClient();
  var lConnection := lClient.Connect('10.6.25.148', 15000);
  var lBytes := Encoding.UTF8.GetBytes('Hi!');
  lConnection.Send(lBytes);
1 Like

Thanks, yes that looks close to what I had. I just want to send a request to a linux box that is apparently running a JSON API on a specific socket and I wanted to have a play, to see what response I get. So essentially it’s connect and if connection is good send a request, then handle the response when it arrives.