Sending a data from android phone to pc? - c#

I am creating a "tracking system" for my android phone. Basically, the phone would transmit it latitude/longitude to a C# program that will receive the coordinates and display it on a map. I managed to get the phone's latitude/longitude coordinates but I need a way to transmit that data to my C# application running in my PC. I know my way around C# and Java but never really got into network programming. Is there a way to do this ?

I'd look into C# Webservices, very powerful. The communication protocol is SOAP (Simple Object Access Protocol) which is a popular and well supported standard.
Good starting reference: Your first C# Web Service

I can't speak to the C# side of it, but if you write a C# server to receive post requests, the Apache HttpClient makes it relatively simple to send requests. There are a bunch of other questions on SO that will help with setting up the client side on your phone if you poke around a bit.

You have different way to do it.
The first is to send data over the cloud to interact through distant server. So the both devices have to be connected to Internet
The second id to send the data over a local network so the data have to be on the same network and have to share their IPs
The third is to use adb forward which allows to build a socket connection between the 2 devices over a USB cable. The requirements are that the phone have to be on debug mode I think and that the driver are installed on the PC so the phone is recognized by ADB.
I can add one more by using a Bluetooth connection. Find information here

The correct way to do it would be to build WCF service which allows many different protocols to receive data. This would could be a very powerful solution that can be extended in future.
The fastest and easiest IMO would be to create ASP.NET MVC application, define a POCO Model for your longitude/latitude and create an action that would take your Model as parameter. Then use HttpClient and HttpPost on android to send the data. The trick here is to name the variables in your post request same as ones you define in your C# Model.

Related

What is the right way to communicate between a C# server and Windows Phone?

Ok so i have a C# server and a windows phone app that acts as a client. The client will have to modify settings on the server, receive images from the server (possibly a video stream) and receive notifications from the server (the best way would be instantaneous, like when someone sends you a message on facebook and you get the notification right away).
I have the server and client set up so they are communicating, they are sending each other an object that is serialized with XmlSerializer (it currently only contains a public String field with public get/set methods). They connect over a socket. This works well if i want to send just simple messages between them, but i assume i'll run into problems when i want to have instant notifications and transfer of images / video streams. How would i go about continuing my work in a proper way?
Consider designing an API solution via web services using RESTful or SOAP services. Personally I suggest using RESTful web services. Here are some kick start links about REST:
http://www.codeproject.com/Articles/255684/Create-and-Consume-RESTFul-Service-in-NET-Framewor
http://www.codeproject.com/Articles/148762/NET-4-0-RESTful-Web-Service-Introduction
http://www.codeproject.com/Articles/21174/Everything-About-REST-Web-Services-What-and-How-Pa
http://msdn.microsoft.com/en-us/library/dd203052.aspx
This is another useful article in MSDN which compares WCF REST and WCF SOAP: http://msdn.microsoft.com/en-us/library/vstudio/hh273094(v=vs.100).aspx
I think if you are looking for two way communication between the client and server then using sockets is the way to go.
As for images you don't need to send the actual image. You can just pass a URL to it and then download it with one of the classes specialized for that.
For near instant notifications you could also take a look at push notifications.
Of course if you don't really need the server to push data to the client then it would be much simpler if you used a REST API as someone else suggested.

Serial Port over the Web

I am starting to program in C# and build applications over the web.
I have a board with a PIC microcontroller that I made that communicates with the PC via USB-Serial converter (FT232).
Now I want to do this: I want to create a website on another computer that allows you to communicate with the PC with the PIC board. Via the other computer I want to be able to control the PIC board.
I think that in order to do that I have to start learning about ActiveX, if I'm not mistaken. Does ActiveX allow me to write on another computer's serial port?
I really want to learn that.
Could you please guide me in the correct direction, and if possible a book or tutorial?
Thank you very much, and sorry for any english mistakes.
No, ActiveX is to let a web page interact with the computer of the visitor of that web page, an old system which should not be used again. Although HTML5 seems to want to reimplement a lot of ActiveX-like functionality again, this is not what you want.
If you create a C# application or service that uses the SerialPort class to talk to your PIC, and use for example a WCF service to accept commands over the internet.
You can then create a web page that lets the user issue commands, while the back end of the web page calls the WCF service to send the command to the PIC.
You could build a website or a webservice which runs on the computer with the PIC board. This website would allow you to send commands to the local attached board.
If you have got a .NET SDK for your board you should be able to wrap all the commands in the service or website.
Might look at something like this product http://www.virtualserialport.com/products/serial-over-ethernet/, if you want to make it look like a local serial port. If that's not necessary, I'd write a service that listened on a socket and simply sent the serial data between the socket and the serial port.

C# - SIP Control

Ok, I have a VOIP Phone. I know the IP address and the port of the phone and have full access to the phone, which I am using to make SIP calls via a SIP trunk.
I basically want to see what is going on on the phone at any given time and I don't know where to start.
If I started, initially, using Wireshark what type of network traffic would I need to look for?
Could I use Putty and view activity on the phone that way?
What part of the .Net framework would provide functionality for interfacing with a VOIP phone?
Thanks
(Most) VOIP phones uses UDP communication, so you would use the UDP functionality in .NET. This can be raw sockets or the UdpClient class, which is a nice starting point.
You can look in Wireshark for UDP communication that has the phone IP as endpoint. You should try to get the network protocol documentation for your specific protocol/phone, or it is likely to take you a very long time to deduce the messages you need to send.
Wireshark has a built-in SIP processor
According to http://www.splicecom.com/document-area/doc_download/272-maximiser-protocol-a-port-information-for-ip-networks they have several protocols providing different information which you can access to achieve what you describe.
Another option is to use the the TAPI provider they offer to access the information you want.
Some starting points for TAPI via .NET:
http://www.codeproject.com/KB/IP/devangpro.aspx
http://www.codeproject.com/KB/dotnet/CShart_TAPI_3x.aspx
http://www.codeproject.com/KB/IP/Video_Voice_Conferencing.aspx
http://msdn.microsoft.com/en-us/library/ms734214.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms734257%28v=vs.85%29.aspx
Another option is to build a SIP proxy which allows you to do all sorts of things including the things you described:
http://www.codeproject.com/KB/cs/SIP_stack_with_SIP_proxy.aspx
http://sipsorcery.codeplex.com/
http://www.independentsoft.de/sip/index.html
http://www.konnetic.com/products/products_sip_sdk_std.aspx
http://www.voiceelements.com/Products/VEToolkit.aspx

How can two C# apps send messages over a WiFi Network?

Lets say I have my C# app installed on 2 laptops connected to a WiFi Wireless Local Area Network.
How can these apps send messages to each other? What method or library can I use? I heard of using sockets but I have no idea how to work with these.
You could use WCF to build a communication pipe between the 2 applications. WCF encapsulates the sockets into a more manageable interface. You can start here.
Basically, you'll want to do it the same way you would in any other language. You'll open a network connection of one flavor or another (raw TCP or UDP, or a higher level protocol like HTTP) with one side acting as a server and the other acting as a client. Then each side can write data through or read data sent by the other side. It's can get pretty complicated from there. If you Google "C# Sockets" or "C# HTTP", etc, you'll find quite a few tutorials on the subject.
This is a very good article on sending C# objects (which could include whatever messages that you want to send) over a Socket connection using the Binary Formatter. Although it is not the most efficient, it is quite easy to grasp and get working.

How to create an IM bot with C#

Is there an easy way to create an IM bot on multiple im networks (aim, gtalk, yim, etc) that can accept and interpet specific commands sent to it to perform a server related task?
Lets say for instance I have a website for managing an rss feed. I want to send a command to an IM bot to add another feed to my collection. the IM bot would associate my screen name with my account from prior setup on the website.
I have done some internal bots for my company using the XMPP (Jabber) protocol, I've used the agsXMPP SDK and the Jabber.NET client libraries, I was looking for APIS to work with YIM, AIM and Windows Live Messenger but I've found only COM exposed APIS, nothing for .NET...
But an idea comes to my mind, with the XMPP Protocol you can configure a local server with IM Gateways, that allow users to access networks using other protocols through your server
I use eJabberd, you can install a variety of transport gateways to connect with other IM protocols (AIM, MSN, ICQ, GTalk...
To GTalk you can connect directly using the libraries I mention...
A sample ICQ gateway:
The short answer to this question is yes this can be done relitivly easily. Sedning and receiving IMs sending, receiving and interpreting requests from the network you wish to communicate on and there are libraries available for each of the major IM protocols to make this easier.
For messenger you can try the DotMsn library, I have used it in the past but at that time it was still quite new and I have not used it since so I can't vouch for it's quality.
Jabber uses the XMMP protocol which is an open-standard so there are bound to be plenty of client libraries available.
If I recall correctly Google Talk uses this protocol or a modified version thereof.
I dont have experience with c# but I have written one for AIM and Gtalk using PHP. http://www.imified.com/ is the best place to start if you looking for a easier way to write an IM bot.
Basically you create an account in imified.com .
Name your bot and link a script.
When ever a message is sent to the bot, imified.com automatically runs this script.
Here is a link for you get you started!
We have professional .NET/COM/VCL library for MSN/Yahoo/ICQ/AIM/GTalk/Jabber. Please take a look at http://www.imcomponents.com/ if you like.

Categories