From my understanding I can only connect to a single service of a certain UUID. I looked in the properties and found that each device had it's own comport and guessed I had to be wrong. I tested multiple connections with 32feet.net and it turns out I can connect and communicate to both at the same time (and receive data).
I read Android: How do bluetooth UUIDs work? . Which mentions I need to the UUID to connect to a serial port service which I do and this is great (https://groups.google.com/forum/#!topic/android-developers/adeBD275u30) this link has the discussion.
I had been under the impression from reading various posts about not being able to connect to multiple headphones / keyboards / mice that bluetooth didn't allow you to connect to multiple services of the same UUID on Android / Iphone. Are these restrictions made by the OS / application?
After reading wikipedia / http://people.csail.mit.edu/rudolph/Teaching/Articles/PartOfBTBook.pdf
that seems to be the case.
Did I just assume this a long time ago and forget that it was assumed from something non concrete?
Device A can connect only one at a time to service S on Device B. Device A can connect to service S on Device B, C, D and E, etc at the same time.
In details a RFCOMM service listens on port number and publishes that port number in a SDP record listed by UUID. Unlike TCP/IP which uses source and destination port numbers in its packets RFCOMM only uses one port number in its packets and therefore only one connection can be active to that port number between a pair of devices.
Related
Many questions relating to port 80 being used have answers saying that there are many programs that use it as their default port. This post mentions some: Skype, IIS, Apache...
Since only one application can listen on any one port at a time - How can that be? And if the answer is that that's only their default port - how will an application know it has to send information to a different port? For example - if iis will listen on port 81 because Skype is listening on 80 - how will anyone requesting a web page know to send the request to theip:81 as opposed to theip:80?
My goal is to have a robust way of setting up a connection between programs, when any hard coded port might fail due to some application already listening on it. The port will only need to be used once in order to communicate what dynamic port will be used for the rest of the session. This is a problem for both network connections and for connecting several applications on the same computer.
Registering with IANA is not always possible, and won't even necessarily solve the problem - someone might still be listening on a registered port. And obviously the solution of "hope for no collisions" - just doesn't cut it.
(I do understand that a connection has two sockets (and a protocol) and therefore one socket can have multiple connections. My question is about listening on a socket in order to establish the connection.)
What I would expect, is there to exist some service on the OS (Windows) that I could register my application with, and receive all incoming traffic with some signature - even if it's simply some magic string. Or perhaps some port where multiple applications can listen concurrently - and all would get every incoming message. But I haven't found anything like that so far.
How can that be? Simply...it's not. Only one application will listen on each port. – Adriano Repetti
Right. When Skype listens on those ports before I start my web-server, the server fails. It took me a while to find out why.
Only one app can listen on a socket in a sane way. The OS allows multiple apps to listen on the same port if you specify special options but that's insane. Accepted connections are then dispatched to different applications in an unspecified (i.e. random) way.
IIS can run multiple web-apps on the same port because it opens the port once in kernel mode and dispatches connections to its worker processes.
I do not believe it is ever possible for multiple sockets to listen on the same (TCP) port. If you try to bind a socket to a port that is already open, you will get an error.
I believe Skype gets around the problem you describe by using their own servers as a rendezvous point. The simple explanation being:
Alice starts her client, connects to the central server, and informs it of what port she is listening on.
Bob starts his client and likewise informs the central server.
Now, Alice wants to connect to Bob, but doesn't know which port to send packets to.
Alice will then query the central server for Bob's port number.
With this information, a direct connection is then established with Bob using that port.
The logic can of course extend to learning the other party's IP address as well as even obtaining public keys.
Note that there's actually a bit more involved with most modern peer-to-peer applications, Skype being no exception. The problem being that most computers are now behind at least one NAT router. Getting two devices each behind their own router to connect to each other is known as NAT traversal - the most common technique having a central coordinating server instruct both clients to simultaneously connect to each other. For more information on this, I recommend Steve Gibson's Security Now!, episode #42
on the port forwarding setup page i just put a comma and add an other port to open. it wont allow you to set up an additional rule with listen port 80 but it will allow you to trigger multiple ports with that one listen port
For TCP, you can only have one application listening on a single port
at one time. Now if you had 2 network cards or created a virtual
interface, you could have one application listen on the first IP and
the second one on the second IP using the same port number.
For UDP (Multicasts), multiple applications can subscribe to the same
port.
one application listening on a single port that's the reason why ports exist. To allow multiple applications to share the network without conflicts.
But there are ways to do what you requested:
You could write a master process, which possesses the port and notifies slave processes using some separation logic.
On Linux and BSD you can set up remapping rules that redirect packets from the visible port to different ones(such as listener app), again by using some separation logic(e.g. redirect according to network origin etc.).
Note: For TCP, you multiple applications can listen on the same socket by using SO_REUSEADDR option before binding but what this does is redirect the incoming connection to only one of the listeners.
I only briefly started working in C# and I'm currently using RS-485 to communicate with some other devices but I don't seem being able to actually get the other devices to respond.
I was wondering if there were any way to write to a specific device using serial communication since it's all connected through COM Port 4.
I already know serial.Write(); but as far as I know it doesn't give you the option to choose which address you wish to send to.
Is there anyone who might know a answar to this question?
Best Regards
Cvr
Thanks for the responses. They helped alot :)
Kristof is correct, but to elaborate a little more:
When communicating with RS232 you simply have two endpoints, your PC and external device. You communicate with the device by sending it commands, or it may even send them regardless. It may be simple ASCII text or binary/hex codes. The way it communicates between the two devices is known as the protocol - and your application must implement this protocol to be able to 'talk' to the device.
RS485 is different than RS232, in that you can daisy chain multiple devices on the same serial port that is connected to your PC. Depending on your device it will have its own protocol that it understands which you will need to study and become familiar. This should be supplied with the devices you are connecting to.
Typically, the protocol will have (at least) the following information:
Device Address - it uses this to distinguish which device you wish to talk to, usually can be set by hardware toggle switches or the like
Command - the actual command that you wish to send to the unit
Data - Any extra data you may need to pass for specific commands
So, an example command you might send to the unit will look like (note this is only an example):
$01FF9A
Where:
01 is the module or devices unique address
FF is the command type
9A is the data
So here, the module with device address 01 will read the command and deduce 'hey you are talking to me' and then process the command information. All other devices will also receive the data, but will realise that it is not destined for itself.
Usually RS485 devices communicate using Hex data, so your application will need to send hex commands to the external devices, and handle the conversion to from for any relevant responses etc. You may need to look at Serial.Write(byte[], int,int) to send hex data to the devices.
For a more detailed explanation of .NET serial port class, refer to http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx
You can create an instance of the SerialPort class.
There you can define baudrate, portname etc.
After calling the Open() method you can read or write data to or from the port.
var port = new SerialPort();
port.PortName = "COM4";
port.Open();
this is my first question here, after searching and reading through many places I have not choice but to ask.
I have a C# application that receives data from a GPS device and stored in a database, I need now is to send a string that contains commands which the device should be interpreted.
This device connects to the Internet over GPRS, I haven't idea how to send this packet over TCP over GPRS because the IP is dynamic.
I hope any suggestions or ideas on how to solve this.
Best regards.
You should do it the other way around - the device should poll the server for instructions. Just make sure the server is accessible.
As you have specified that you have developed a C# application to read the GPS data through GPRS that means you are running C# application on a public/static IP.
Nwo as soon as you get a request from the GPRS client, you get the DHCP IP address of the remote endpoint too.
Once you have that endpoint and socket open, you can transmit any data to the GPS device back.
Assuming that your GPS device is having some microcontroller to drive the GSM/GPRS modem.
I'm going to make an assumption here that the 'Device' is some kind of mobile phone connected to a standard GSM network?
If it is, then the short version of the story is "Forget it" even if the IP wasn't dynamic, you simply wouldn't be talking to the IP of your device, you'd actually be talking to the IP address of your providers GGSN, and for a standard consumer connection this is going to be where the buck stops.
Now that said, IF you have the budget, and all your devices (Assuming multiple ones) are with the same carrier, then you can approach the carrier and request a dedicated APN (Access point name) essentially what this is , is the mobile network equivalent of a DNS record, or at least similar enough to use that analogy anyway.
When you set up your data connection on your device you may recall having to enter something like 'pp.vodafone.com' or 'INGhub411.o2-uk.inbound' we'll this is your actual APN, and if you have a custom one they your devices can be set up so that the IP the presents itself at the GGSN actually has a static route back to the individual device in the suppliers GSM network.
As a general rule of thumb however on consumer grade connections this is not enabled and hence there is no ingress available to the individual device.
As zmbq says, the ONLY option you have is for the device to keep polling the server on a regular basis, and yes unfortunately that is going to be very unforgiving on the battery.
of course there is one other way of approaching this, and that's to have the device open a socket directly to your server then keep that socket open. Once the socket is open, 2 way communication can be performed across the link, unfortunately your going to also have to write all the code to manage this connection including, but not limited to monitoring the connection to make sure it's still open and re-establishing it if it's not, something which is incredibly important on a mobile device.
I am looking for something to test my app. The app is a weight logger, built in .net 3.5 - it is connected by rs232 to an electronic weight, but the problem is that I don't have it at home.
I wanted to emulate the traffic and data with my app, but I have a problem: I can't get 2 apps on 1 port.
Please help.
These are the tools you need:
com0com: Creates two virtual COM Ports which are connected to each other
Just connect your receiver application with the first one and your mock weight application with the second one.
Serial Port Monitor: If you need to sniff into some serial port connection to find out how another application communicates with some serial device.
Update
The storing and filtering is just to specific to your concrete project, so that you wouldn't find anything "out of the box". But you have two possibilities to store the data.
Within your application implement some kind of wrapper class for your serial port. Every read and write access to the serial connection goes through this class. Then this class sees everything and can dump the whole traffic into a file or somewhere else. Additionally you could also implement some kind of filter mechanism.
Instead of putting the dump and filter logic into your program, write it as an application. This application connects to two COM ports. The first is the real serial port. The other is a virtual from the com0com driver. Your application that normally communicates with your serial device will now be connected to the second com0com driver. So you're able to dump and filter anything that flows through your serial port.
We have a scenario where multiple devices are connected to one com port. Each device has an access code, which is manually defined within the device.
Can I access all the connected devices with/by access code in C#?. Does anybody have any idea as to how to do this?
In my case multiple devices are connected with single port but slave addresses are different..how can i access all the slave address in C# code for restricting that another device shudnot have same slave address?
Take a look at an article - Serial post in C# and Tutorial
Jaswant,
Where I work, we have some devices that are accessed over RS232 via a .net forms app. We have multiple devices connected via the same serial line at the same time.
As long as the devices on the end of the cable:
a) respond when spoken to (i.e. directly addressed) - and at no other time
b) use connectionless serial communications (i.e. no handshaking)
then I doubt that you will have a problem doing this with your devices.
I'm assuming you will have to 'address' your device like we do, i.e. every block of data sent down the line is in a specific format (bit like a TCP header) e.g.
byte description
---- -----------
00 command
01 address
>=02 data
All devices receive all comms, but only act upon instructions and respond if the address in the data matches the address on the device.