using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace RestaurantProgram
{
public partial class main : Form
{
public main()
{
InitializeComponent();
}
byte[] myReadBuffer = new byte[1024];
StringBuilder myCompleteMessage = new StringBuilder();
int numberOfBytesRead = 0;
private void bt3_Click(object sender, EventArgs e)
{
main f1 = new main();
stock f2 = new stock();
this.Hide();
f2.Show();
}
private void bt1_Click(object sender, EventArgs e)
{
main f1 = new main();
alltable f3 = new alltable();
this.Hide();
f3.Show();
}
private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void bt5_Click(object sender, EventArgs e)
{
main f1 = new main();
setting f5 = new setting();
this.Hide();
f5.Show();
}
async void bt7_Click(object sender, EventArgs ea)
{
bt6.Enabled = true;
TcpListener tcpListener = new TcpListener(IPAddress.Any, 8000); //ประกาศใช้ socket server
tcpListener.Stop();
}
async void bt6_Click(object sender, EventArgs ea)
{
Button bt6 = sender as Button;
bt6.Enabled = false;
TcpListener tcpListener = new TcpListener(IPAddress.Any, 8000); //ประกาศใช้ socket server
tcpListener.Start();
await Task.Run(() =>
{
while (true)
{
TcpClient tcpClient = tcpListener.AcceptTcpClient();
MessageBox.Show("มีเครื่องลูกข่ายติดต่อเข้ามาแล้ว");
NetworkStream ns = tcpClient.GetStream();
if (ns.CanRead)
{
//byte[] myReadBuffer = new byte[1024];
//StringBuilder myCompleteMessage = new StringBuilder();
//int numberOfBytesRead = 0;
while (true)
{
numberOfBytesRead = ns.Read(myReadBuffer, 0, myReadBuffer.Length);
myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));
MessageBox.Show("You received the following message : "+ myCompleteMessage);
}
}
else {
MessageBox.Show("Sorry. You cannot read from this NetworkStream.");
}
}
});
}
}
}