Sync clock over ethernet using custom message - c#

I have a setup where I have some PLC's connected to a windows PC, I am doing the code on the windows PC in C#. I want to be able to sync the clock of the PLC's with the PC.
The PLC don't support the windows built in time sync services, so I need to do it myself.
My first idea is to just send a message (TCP) to the PLC periodically containing the time of the windows PC. I don't need to be precise on milliseconds, a second would be fine. So my first guess is that this would be enough.
But now I think that if it wasn't so difficult it could be cool to make something that took the time of sending a message on TCP into account to get a more precise sync.
Any ideas on how to achieve that?

Since TCP has some overhead and the amount of data is pretty small, why not use UDP?
Send a UDP request to the server, receive the current time as answer and use half of the answer time as transport delay - rough but easy to do.

Related

How does multi player communication work from a client to a poker server?

I just started to work with client-server communication and I created a poker game that works on Android and iPhone and connects with a C# server. Right now I'm using PubNub to send and receive messages but there are either one of two problems with this:
I need to poll the sever and get the table status all the time so there will be a lot of messages which means that the server needs to send more messages (more overload) and a higher cost (as PubNub pays per message)
(or)
The table will not always be 100% updated on the client (Android/iPhone)
So my question is how do bigger poker sites like PokerStars handle the communication? Do they set up sockets and send the information all the time to the connected users to that connected table?
Any information about creating this kind of communication between one server and several mobile devices (and also Windows C# clients) would be highly appreciated.
I cannot give you an answer to your question but my approach would be using a tool like WireShark and try to find it out by analyzing the (amount of) packets that are exchanged.

Real time communication

I have the same dilemma as the one who posted this topic, Real-time communication with WCF
except that my problem is not about games programming. I would like to know what's the best method to use to be able to have a real time communication in between two windows applications (server-client). I am using visual c++/c# to date and i would like to be able to display all the Feeds that are being received by my server to the client in real time.
I have started trying to use .NET remoting but in my continuous research, it appears that it will use SOAP-http, and might affect the speed of the communication. My server and client will communicate using the internet and .NET remoting does not permit the use of TCP Channel when communicating in between a firewall or the internet.
Your inputs will be greatly appreciated.
I guess it depends on your escenario, if you want "real-time" and you are willing to lose some packages in the process you are better with UDP, take a video conferencing tool for example, by the time you recover your slow packages you will have to move and display the next frame in the video or audio; that is a good example for the use of UDP. This is the reason why UDP is much faster than TCP.
If however, you are not willing to lose a single bit of your message, then TCP was made for you because if you lost a package the protocol will request it again to have your complete message as complete as possible.
Additionally it depends on the way the communication is being sustained, is the information flowing from one to many?, from many to many?, one to tone?
Take NetNamedPipeBinding for instance, this will be much faster process, but is only deployed in a single machine but accross processes. Whereas NetMsmqBinding will help you to build queues and it will be amazingly reliable and scalable for scenarios where your load will be a massive number of connections.
In the end, it all boils down to your concrete escenario and your business goals.
Hope it helps
If you are willing to do your own message parsing, you can use standard TCP sockets with the TcpClient and TcpListener classes. If your data is already a serializable object, you could serialize it into a text stream and just send it over the socket, deserializing it on the client side.
To get it to work over the internet, the server needs to have the port forwarded on your router, the client would just attach to the server's public IP. You would obviously need to add an exception in your firewall for this port as well.
The biggest problem with WCF and large data is setting up the streaming, by default WCF sends everything at once, which isn't practical for large files.

How to make perfect client-server communication program using iPhone and C#

I have built a iPhone application, which capture the voice and streamed to server using NSOutputStream instance. Once the stream stops, iPhone sends a text message as "---end---" to the server and starts to listing on NSOutputStream.
When server(built using C#) captured the "---end---" message, it does some processing and write back the text to the client. Once client receive the end message it close NSOutputStream and NSInputStream connections.
Every time, before send the "end" message I put the application to sleep for 0.5 sec. Then I can guaranteed the end message is not mix with other data. This system works well with the simulator and in my network (100Mbps).
However, when I connected the whole application to slow network (1.2 Mbps), the whole communication went vanished. Sometimes the end message is mixing with voice data as similarly the end message is concatenated with the text sending from the server.
But when I change the thread sleeping time for 3 sec in server and client, the error occurrence rate was reduced.
I know that this might be a issue of design my network client-server communication protocol. But I cannot figure out how to fix it exactly.
Can anybody explain me, how can I overcome from these issues ?
Figure out how to wait for the transfer to complete, instead of adding an arbitrary sleep time.

Webservice for serial port devices

I want to create a remote webservice for an application that is now avaliable only localy. This application controlls three devices (each is controlled separately) connected on serial port. The problem is that I don't know how to take care of passing back information that a device return requested data. For example - I send move command to the motion device (which is very slow and can take a minute or more). Can I just set a big timeout on the client side (and server side) and return for example a true/false if operation is completed or is this a bad idea? Is SOAP with big timeouts ok?
And the other question is if Mono on Linux (Ubuntu 9.10, Mono 2.4) is stable enought for making a web service or should I chose Java or some other language?
I'm open for recommendations.
Thanks for your help!
Using big timeouts is not a good idea. It wastes resources on both the server and the client and you will not be able to detect a "true" timeout condition, when the server is unavailable for example, before the allocated timeout expires.
You really have two options. The first is to use polling. Return immediately from the motion request command, acknowledging the reception of the command (and not the completion of it). Then send requests in regular intervals, asking whether the command is completed or not.
The other alternative requires the client to be able to register a callback endpoint, which the server will call when the motion completes. This makes the whole process asynchronous, but requires the client to be able to operate in server mode. This is very easy to do with WCF - I don't know however if this functionality is available in Mono.
Not directly related to your question..., but consider com0com and its friends hub4com and com2tcp.

Getting a notification when my system freezes

I have a minor problem where my (new) computer tends to completely freeze up. Am not sure when it happens exactly but the 6 times that it did happen during the last 4 weeks, it could have been related to a very long rendering task that eats up lots of RAM. (Am actually pretty sure that this rendering engine is causing this problem.) Anyway, I don't really care about what causes the problem. I can repeat it by having the same image rendered again and waiting about 4 hours for it to finish. And I can avoid it by making a minor adjustment to the rendered image which somehow seems to solve it all. It's likely a bug in the rendering engine.
And when I say Freeze, I mean that everything stops responding. Keyboard, mouse, disks, they all just stop and the image on my screens are frozen. I don't get a BSOD or automated reboot.
I don't mind the freeze-up, but I would like to receive a warning when the system does freeze up. So I was thinking about a simple solution that should warn me when it does freeze up again. To do so, I want to use an old SmartPhone (HP IPAQ) which runs Windows Mobile 6 and connect it to my computer through one of the USB ports. It would just continue to communicate with my computer to check if it's still alive. When the computer doesn't respond for 5 minutes, it will assume the system is frozen and would have to send a signal to me. Basically, I want it to send me an SMS message to my other phone. Well, consider the SmartPhone to be a kind of lifeguard...
Anyways, I am quite familiar with software development, just don't know where to start with this application. I will be using the .NET Compact Framework and need some pointers in the right direction to do the following:
1) How to connect to a service on another PC using the USB connection and not some wireless Internet connection? (And definitely NOT any Internet over GSM options, since it's just a prepaid card that I'm using for this phone.)
2) How to send an SMS message from this phone to my other phone?
3) Are there already some existing solutions similar to this thing I just came up with, which could save me some time programming?
I used to have an iPaq pocket pc and based on what i remember when you hook them up to the pc they pick up an IP address.
That IP address is the key to your problem,
your computer could ping your pocket pc's ip as a heartbeat. that way you can be sure that you aren't going through GSM since the Desktop is calling the handheld. How to: Create a Socket Listener your socket listener would be listening on your pocket pc if it doesn't get any messages in a set period of time it would trigger the alert winch would send out your SMS.
You could also do the reverse, where your pocket pc would be pinging your desktop, just make sure that you are using the local IP to avoid traffic over GSM
Sending SMS using compact framework
Send SMS Sample
1) You can connect to a USB port as a COM port - many examples on how to do this especially around using GPS. Write an app for your pc to listen to USB for a message and respond. Write the app on the phone to periodically send a message to the PC and get a response.
2) There should be an API for the phone to send an SMS.
3) Not that I know of, the closest being anything that communicates on USB such as I mentioned with GPS-enabled devices.
Good luck - I know (since I have worked with all the technologies you are talking about) that I wouldn't have a problem making this, but for those without that experience it could get tricky.

Categories