I want to do the following logic on my WPF Desktop application that will;
This is the TCP server program that echoes your sent data back to you.
Start echotool as follows:<br>
echotool /p tcp /s 12345
It must first have two buttons one start, stop, processed. The status bar must show these as details to the user.
What I have tried:
Client code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Threading;
using System.Net.NetworkInformation;
using WPFclient;
namespace WPFClient
{
public partial class MainWindow : Window
{
protected ClientProp WpfClient_;
public MainWindow()
{
InitializeComponent();
}
private void Btncnnct1_Click(object sender, RoutedEventArgs e)
{
TxtBoxIp1.Text = "192.168.0.150";
this.WpfClient_ = new ClientProp(ipAddress: (this.TxtBoxIp1.Text), portNumber: 138);
this.WpfClient_.BeginPrepareTCPClient();
WpfClient_.Connect(IPAddress.Parse(this.TxtBoxIp1.Text), port: 137);
TxtBoxInfo1.Text = "connected" + Environment.NewLine;
}
private void BtnSnd_Click(object sender, RoutedEventArgs e)
{
Byte[] data = System.Text.Encoding.ASCII.GetBytes(TxtBoxMsg1.Text);
NetworkStream networkStream = WpfClient_.GetStream();
StreamWriter stream = new StreamWriter(TxtBoxMsg1.Text);
stream.Write(TxtBoxMsg1.Text, 0, TxtBoxMsg1.Text.Length);
TxtBoxInfo1.Text += $"Server : {TxtBoxMsg1.Text}{Environment.NewLine}";
}
Server Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
namespace ServerWPF
{
public partial class MainWindow : Window
{
private string line;
public MainWindow()
{
InitializeComponent();
}
private void BtnStrt_Click(object sender, RoutedEventArgs e)
{
TxtBoxIp.Text = "192.168.0.150";
TcpListener server = new TcpListener(IPAddress.Parse(TxtBoxIp.Text), port: 137);
server.Start();
TcpClient client = server.AcceptTcpClient();
TxtBoxInfo.Text = "Server Connected" + Environment.NewLine;
BtnStrt.IsEnabled = false;
BtnSend.IsEnabled = true;
NetworkStream stream = client.GetStream();
StreamReader reader = new StreamReader(client.GetStream(), Encoding.UTF8);
}
private void BtnSend_Click(object sender, RoutedEventArgs e)
{
}