Click here to Skip to main content
15,557,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
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:
C#
private void getbarCode()
        {
            byte[] data = new byte[1024];
            int receivedDataLength = lidhje.Receive(data);
            numberCodeBar = Encoding.ASCII.GetString(data, 0, receivedDataLength);
        }



Sending data to device:
C#
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.
Posted
Updated 10-Jun-15 0:45am
v2
Comments
[no name] 10-Jun-15 5:57am    
Have you got a multithreaded server? http://www.codeproject.com/Articles/2477/Multi-threaded-Client-Server-Socket-Class
AldoBlack 10-Jun-15 6:00am    
It is in C++ . I do not know C++ . I used to learn only on university. :/
[no name] 10-Jun-15 6:07am    
Initiative needed - CP has dozens of socket server articles in all languages - just pick one: eg http://www.codeproject.com/Articles/416448/TCP-Socket-Off-the-shelf
AldoBlack 10-Jun-15 6:44am    
I did see the articles but i can not understand. :/

1 solution

I would suggest to write down one broker service/ message queue which will collect product scan results from the devices in async manner and then fetch it to the price service to return appropriate price of product.
 
Share this answer
 
Comments
AldoBlack 10-Jun-15 8:09am    
Hmmmm, i'm sorry but I did not understand. Do you have any sample code please? :/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900