Here's a little Powershell for you... should be compatible with any version of PS... maybe PSv2 or better. Works with either host names or IP addresses.
Function Send-StringOverTcp (
[Parameter(Mandatory=$True)][String]$DataToSend,
[Parameter(Mandatory=$True)][String]$Hostname,
[Parameter(Mandatory=$True)][UInt16]$Port)
{
Try
{
$ErrorActionPreference = "Stop"
$TCPClient = New-Object Net.Sockets.TcpClient
$IPEndpoint = New-Object Net.IPEndPoint($([Net.Dns]::GetHostEntry($Hostname)).AddressList[0], $Port)
$TCPClient.Connect($IPEndpoint)
$NetStream = $TCPClient.GetStream()
[Byte[]]$Buffer = [Text.Encoding]::ASCII.GetBytes($DataToSend)
$NetStream.Write($Buffer, 0, $Buffer.Length)
$NetStream.Flush()
}
Finally
{
If ($NetStream) { $NetStream.Dispose() }
If ($TCPClient) { $TCPClient.Dispose() }
}
}
Send-StringOverTcp -DataToSend 'foo!' -Hostname google.com -Port 80
I wrote this very hastily... you might want to put extra parameter validation and error trapping in there, but you get the idea. Also worth considering is that Windows uses UTF16 LE encoding by default, so characters are typically "wide," as opposed to many other systems which use narrow characters. So you may want to encode the string as Unicode instead of ASCII, etc. Depends on what you're using it for.
Or if you'd rather make it as simple as your Netcat example, just... download Netcat for Windows.