Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows .NET socket
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.
 
 Thread th_main,th_sub;
bool bool_Start_subTH;
 Socket Socket_Client ;
TcpListener objListener;
  
 

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 23-Jun-13 23:44pm
arunrv2.5K

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 24 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100