Note that there are some explanatory texts on larger screens.

plurals
  1. POSend plain text via sockets in .NET
    text
    copied!<p>I'm writing a replacement for an old library we use at the office to communicate with a rather clumsy and old custom-made C++ framework that takes requests via sockets in order to communicate with a bunch of other systems. The problem is that it will only take plain text messages containing a string which must be formatted in a very specific way.</p> <p>The problem I'm facing is that I haven't found so far a way of sending plain text through the socket. The Send method of the socket will only take byte arrays, and while the listening point receives the data, it gets there completely scrambled, and there's no way I can mess with that in order to convert the byte array back to plain text. I need to be able to send plain text, not byte arrays.</p> <p>This is the Connect and the Send method I have so far:</p> <pre><code> Public Sub Connect(Optional ByVal pHostName As String = "", Optional ByVal pPort As Integer = 0) If pHostName.Trim &lt;&gt; "" Then mHostName = pHostName If pPort &gt; 0 Then mPort = pPort Try Dim ipep As IPEndPoint If IsIPAddress(mHostName) Then ipep = New IPEndPoint(IPAddress.Parse(mHostName), mPort) Else ipep = New IPEndPoint(IPAddress.Parse(Dns.GetHostEntry(mHostName).AddressList(0).ToString), mPort) End If mSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) mSocket.Connect(CType(ipep, EndPoint)) mState = eState.Connected RaiseEvent Connected() mDataTimer.Start() Catch ex As Exception Me.Close() Throw ex End Try End Sub Public Sub SendData(ByVal pBytes() As Byte) mSocket.Send(pBytes) End Sub Public Sub SendString(ByVal pString As String) Dim bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(pString) mSocket.Send(bytes) End Sub </code></pre> <p>Any help will be appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload