none
Send data to Unix Server RRS feed

  • Question

  • Hi,

    I have a .net app that concatentes all the fields on my winform.
    In this case 910 characters. I need to send the string to a port on a unix system. I am stumbling over the length. I get the string length fine and pretend it to my string as 0910 2 byte asci. What I need is 038E binary, then my string of 910 characters. How would I send the proper length to the host?

    Thanks
    MW

    <form action="https://www.facebook.com/ajax/ufi/modify.php" class="commentable_item" data-ft="{" id="u_fetchstream_10_13" method="post" rel="async" style="margin:0px;padding:0px;" tn":"]"}"="">
    </form>
    Wednesday, July 17, 2019 9:34 PM

All replies

  • Hi,

    How do you send data to Unix Server?

    Dim message As String 
    
        'Connect to Server 
        Dim port As Int32 = 23 
        Dim client As New TcpClient(unixServer, port) 
    
        'Send username to login to server 
        message = userName & " \n" 
        Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message) 
        Dim stream As NetworkStream = client.GetStream 
        stream.Write(data, 0, data.Length) 
        TextBox2.AppendText("Sent: {0} " & message & vbCrLf) 
        data = New [Byte](256) {} 
        Dim responseData As [String] = String.Empty 
        Dim bytes As Int32 = stream.Read(data, 0, data.Length) 
        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes) 
        TextBox2.AppendText("Recieved: {0} " & responseData & vbCrLf) 
    
        'Send password to login to server 
        message = passWord & " \n" 
        data = New [Byte](256) {} 
        data = System.Text.Encoding.ASCII.GetBytes(message) 
        stream.Write(data, 0, data.Length) 
        TextBox2.AppendText("Sent: {0} " & message & vbCrLf) 
        data = New [Byte](256) {} 
        bytes = stream.Read(data, 0, data.Length) 
        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes) 
        TextBox2.AppendText("Recieved: {0} " & responseData & vbCrLf) 
    
        'Send return key to start new line 
        message = "\n" 
        data = New [Byte](256) {} 
        data = System.Text.Encoding.ASCII.GetBytes(message) 
        stream.Write(data, 0, data.Length) 
        TextBox2.AppendText("Sent: {0} " & message & vbCrLf) 
        data = New [Byte](256) {} 
        bytes = stream.Read(data, 0, data.Length) 
        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes) 
        TextBox2.AppendText("Recieved: {0} " & responseData & vbCrLf) 
    
        'Get directory listing 
        message = "ls -lrt" 
        data = New [Byte](256) {} 
        data = System.Text.Encoding.ASCII.GetBytes(message) 
        stream.Write(data, 0, data.Length) 
        TextBox2.AppendText("Sent: {0} " & message & vbCrLf) 
        data = New [Byte](256) {} 
        bytes = stream.Read(data, 0, data.Length) 
        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes) 
        TextBox2.AppendText("Recieved: {0} " & responseData & vbCrLf) 
    
    
        stream.Close() 
        client.Close() 

    Best Regards,

    Alex



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 18, 2019 7:17 AM
    Moderator
  • Hi Alex,

    I used the code above as an example the last time I tried to tackle this problem. I even have an old post about it:

    send-binary-data-to-unix

    I left that company where I was trying to get it to work, after a few years I'm back at the same company, and guess what, the problem still exists.

    I am able to send my concatinated string to the unix host and am able to get an IP traces of it. The whole issue is that the unix server requires a length indicator formatted as msb_bin2. I can change the server to accept ascii2 and get it to work, but I can only do that for testing.

    I have a IP trace of a message that works and it has the length as 01A4 which equates to the string length. I can't just tag 01A4 on the front of my string as it assumes its part of the string. I can only manage to send 0420 as the length and the host just ignores the message.

    Hope that made sense.

    Thanks

    MW

    Friday, July 19, 2019 12:01 AM