I want to send some data from Arduino server to C# application and show it in a textbox. But when I try to read the data from C# I only get the first line of sent data.
This is Arduino side code:
IPAddress ip(192, 168, 1, 85);
EthernetServer server(64000);
Ethernet.begin(mac, ip);
server.begin();
void setup() {
Serial.begin(9600);
}
void loop() {
if(EthernetClient client = server.available()){
client.println("data1"); //I only get this line in C#
client.println("data2");
client.println("data3");
client.println("data4");
client.println("data5");
client.stop();
}
}
I think there must be some problem in my C# side code.
C# side code:
void ReceiveData()
{
client = new TcpClient("192.168.1.85", 64000);
NetworkStream stream = client.GetStream();
Byte[] dataReceive = new Byte[256];
String responseData = String.Empty;
Int32 bytes = stream.Read(dataReceive, 0, dataReceive.Length);
responseData = System.Text.Encoding.ASCII.GetString(dataReceive, 0, bytes);
txtReceive.Text += responseData;
stream.Close();
}
Output:
data1