0

My TCP Client should:

  1. accepts host, port and a text string.
  2. connects to a host/port and sends the string (+ two lines feeds \r\n\r\n )when you click a button.
  3. then reads the results and puts the results back in a text box.

The problem that I get a result of the port and string , BUT I DON'T GET ANYTHING ABOUT THE HOST.

This is what I've got so far:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.IO;
    using System.Net.Sockets;


   namespace TCP_Client
   {
public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {

        string port = port1.Text;
        int myParsedInt = Int32.Parse(port);
        System.Net.IPAddress[] adresslist = Dns.GetHostAddresses(host1.Text);

        Socket connectSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        connectSocket.Connect(adresslist[0], myParsedInt);
        System.IO.StreamReader connectionRead = new System.IO.StreamReader(new NetworkStream(connectSocket));

        connectSocket.Send(System.Text.Encoding.UTF8.GetBytes(sendText.Text + "\r\n"));
        while (connectionRead.Peek() >= 0)
        {
            this.textOutput.AppendText(connectionRead.ReadLine() + "\r\n");
        }

        connectSocket.Close();
    }

    private void textOutput_TextChanged(object sender, EventArgs e)
    {

    }

    private void host1_TextChanged(object sender, EventArgs e)
    {

    }

    private void port1_TextChanged(object sender, EventArgs e)
    {

    }

    private void sendText_TextChanged(object sender, EventArgs e)
    {

    }
}
}
4

1 に答える 1