Why are you trying to receive TCP data through UDP client? It's never going to work.
I want get gps device detail like(latitude and longitude) in c#.How i can get ?Please suggest me.
What protocol does your GPS device use? You need to create a server, not a client, to receive data.
Hi Anton
I am new in gps device but i have good experience in c#.Please write a step how get data from
gps device in c# or share me sample code if you have.
Thank you very much for spending time for me and helping me.
It has nothing to do with GPS devices. It's just basic networking. Does your device use TCP or UDP?
I don't have much C# experience, so I can't provide any code samples, but I'm guessing that you need to use TcpListener
class if your device is using TCP protocol (most popular option). UdpClient
is probably a right class in case your device uses UDP protocol.
Hi Anton
Its using tcp and port 5001.Its showing error when i am trying to use tcp listener class.
Please share me code in php or in c#.That will helpful for me.
Thanks .
I don't have code examples in PHP or C#, but I'm sure you can easily find some on Google.
Hi Anton
I have written code for server & client both but when i am running it on my local machine its showing error.
//---------------server code ------------
try {
IPAddress ipAd = IPAddress.Parse("xxx.xxx.xxx.xxx"); //This is ip of server where gps device configured
// use local m/c IP address, and
// use the same in the client
/* Initializes the Listener */
TcpListener myList=new TcpListener(ipAd,5001);
/* Start Listeneting at the specified port */
myList.Start();
Console.WriteLine("The server is running at port 8001...");
Console.WriteLine("The local End point is :" +
myList.LocalEndpoint );
Console.WriteLine("Waiting for a connection.....");
Socket s=myList.AcceptSocket();
Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
byte[] b=new byte[100];
int k=s.Receive(b);
Console.WriteLine("Recieved...");
for (int i=0;i<k;i++)
Console.Write(Convert.ToChar(b[i]));
ASCIIEncoding asen=new ASCIIEncoding();
s.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement");
/* clean up */
s.Close();
myList.Stop();
}
catch (Exception ex) {
Console.WriteLine("Error..... " + ex.StackTrace);
}
}
//-
----------------client code
try {
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");
tcpclnt.Connect("109.237.27.244",5001);
// use the ipaddress as in the server program
Console.WriteLine("Connected");
Console.Write("Enter the string to be transmitted : ");
String str=Console.ReadLine();
Stream stm = tcpclnt.GetStream();
ASCIIEncoding asen= new ASCIIEncoding();
byte[] ba=asen.GetBytes(str);
Console.WriteLine("Transmitting.....");
stm.Write(ba,0,ba.Length);
byte[] bb=new byte[100];
int k=stm.Read(bb,0,100);
for (int i=0;i<k;i++)
Console.Write(Convert.ToChar(bb[i]));
tcpclnt.Close();
}
catch (Exception ex) {
Console.WriteLine("Error..... " + ex.StackTrace);
}
}
What is the error? I guess you are doing something wrong if it shows an error.
I am running both client and server on my local machine .Is this work?.Or i have to run both on server
where device configured?.
I think you need to learn some basics about computer networks first and TCP protocol in particular. This is not a right forum for these kinds of questions.
If you have any questions specific to GPS tracking devices, you are welcome.
Hi Guys
I have configured device TK103 on tcp ip and port .How i can get response from that device ?.I am
using c# but i am not able to get response.This is the sample code .IP and port using of my server.
Please suggest me where i am wrong.