Click here to Skip to main content
15,077,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello every one,

I am working on a GPS vehicle tracking project . Here the device used to send Latitude and Longitude signals to a particular IP (Static IP) in 5000 port there are totally 17 devices.So my problem is when all the 17 device are activated I am not getting the readings form all device in a proper time duration.
Means if I got the readings of Device 1 i will continuously get 5 to 6 readings form that device after that when Device 2 i will continuously get 5 to 6 readings similarly it goes on . What I am going to say here is all the device transmit the readings (Latitude,Longitude) for every 1 mint to my IP but when i get the Signal form device I will get only form device 1 after few 5 to 6 mints Device 2 then 3 . So my problem is my application is loosing the packets . means when my application is receiving data from Device 17 . Application is receiving the last 5 to 6 mints readings but it has lost the readings from past 10 to 30 mints. So how can I get the signal from all the devices parallely to same port using one socket .

Here is the code how I Implemented.

C#
 Thread th_main,th_sub;
bool bool_Start_subTH;
 Socket Socket_Client ;
TcpListener objListener;



C#
private void Form1_Load(object sender, EventArgs e)
        {
            bool_Start_subTH=false;
            th_main = new Thread(GetDataFromClient);
            th_main.Start();

        }

void GetDataFromClient()
{

objListener = new TcpListener(5000);
 objListener.Start();
    while (th_main.IsAlive)
{
 Socket_Client= objListener.AcceptSocket();
if(!bool_Start_subTH)
{
  th_sub=new Thread (SubFunctionThread);
th_sub.start();
bool_Start_subTH=false;

}
   
}

}

void SubFunctionThread()
{
     while(th_sub.IsAlive)
{
           if(Socket_Client.Avilable>0)
{
                    byte[] something = new byte[Socket_Client.Available];
                    Socket_Client.Receive(something);
                    string strmessage = Encoding.ASCII.GetString(something);
                    Listbox1.Items.Add( strmessage);               
}


}
}


Here is my code . Is it right if not then suggest me how can I solve my problem .If any example is there means it will be very helpful for me


Thanks in Advance.
Posted

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