首次使用Beetlex ,做个记录
using BeetleX;
using BeetleX.Clients;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Net;
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;namespace InfusionBagSmartLabeler
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}private void Button_Click(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Hello, world!");
var newWindowThread = new Thread(connect);
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = true;
newWindowThread.Start();
//connect();
//MessageBox.Show("connect OK");
}private void connect()
{
string IP = ConfigurationManager.AppSettings["ServerIP"];
int Port = Convert.ToInt32(ConfigurationManager.AppSettings["ServerPort"]);TcpClient client = SocketFactory.CreateClient<TcpClient>(IP, Port);
client.Connect();
var stream = client.Stream.ToPipeStream();
while (true)
{
Debug.WriteLine("Enter Name:");
// Console.Write("Enter Name:");
var line = "easyboot" + DateTime.Now.ToString();// $"{DateTime.Now}";// Console.ReadLine();
client.Stream.ToPipeStream().WriteLine(line);
client.Stream.Flush();Debug.WriteLine("ReceivBytes " + client.ReceivBytes);
try
{
var read = client.Receive();
// read.
var line3 = read.ReadToEnd();
Debug.WriteLine(line3 + "----" + DateTime.Now.ToString());
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}}
}
}