Hello,
I have 6 devices, price checkers. I have a project which the client in a supermarket will scan a product on this device and it will return the price of the product. I have managed to connect with one device, get the bar code and send data. But I can not seem to do to connect with multiple socket connection.
This is the code when I receive and send data:
Connecting with the device:
private void connect1(string adip, int porta)
{
try
{
IPEndPoint ip = new IPEndPoint(IPAddress.Parse(adip), porta);
connect1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
connect1.Connect(ip);
}
catch (System.Net.Sockets.SocketException se)
{
MessageBox.Show(se.Message);
}
}
Getting the barcode:
private void getbarCode()
{
byte[] data = new byte[1024];
int receivedDataLength = lidhje.Receive(data);
numberCodeBar = Encoding.ASCII.GetString(data, 0, receivedDataLength);
}
Sending data to device:
private void sendData(string price1)
{
try
{
Object objData = price1;
byte[] price = System.Text.Encoding.ASCII.GetBytes(objData.ToString());
connect1.Send(price);
}
catch (System.Net.Sockets.SocketException se)
{
MessageBox.Show(se.Message);
}
}
I want to make this with muliple decives in the same time. I have searched Google but no luck.