I'm trying to communicate with server, using TCP CLient. But to communicate, there are connection rules:
- Whenever the reader is going to start a communication, mark 1 must be placed on its output.
- This signal is felt by the server as a connection request indication and is only valid after 1 second of stabilization.
- Once the connection request is accepted, the server starts sending the ENQ signal chars. (ENQ = 05 Hexadecimal)
I think I need to use some "sleep" function for 1 second and sending 1 as mark. So I implemented the following example I had:
public void Initialize(string ip, int port)
{
try
{
tcpClient = new TcpClient(ip, port);
if (tcpClient.Connected)
Console.WriteLine("Connected to: {0}:{1}", ip, port);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Initialize(ip, port);
}
}
public void BeginRead()
{
var buffer = new byte[4096];
NetworkStream ns = tcpClient.GetStream();
ns.ReadTimeout = 1000;
ns.BeginRead(buffer, 0, 9, EndRead, buffer);
}
class Program
{
static void Main(string[] args)
{
var client = new Client();
client.Initialize("192.168.0.250", 2180);
client.BeginRead();
Console.ReadLine();
}
}
When I run this code, show the message: "Connected to 192.168.0.250". Now following the rules, I need to receive the ENQ (05 Hexa) signal from the server. How do I receive this signal?