Custom SQL Server driver - c#

I had a crazy thought about writing my own SQL Server driver to make it work something like non-blocking http client, so it won't be thread thirsty and could handle lots of db queries within one thread.
I tried to look over google for some guidelines about implementing SQL Server client protocol, but found none really, where do those guys get information about it when they write own implementations for PHP or python?
I need a really low level to be documented so I can implement all phases of working with a connection through sockets. And would be really nice to have a an example in c# language. :)

I regularly use the existing Async functionality in the .NET SQLClient, this easily allows additional threads to handle the database operations.
I'm not sure how you would really handle multiple non-blocking operations in the same thread.

MSSQL Protocol specs:
http://www.microsoft.com/downloads/details.aspx?familyid=91ef5106-944a-41e1-b3a0-5bd3f2356f32&displaylang=en
Without knowing anything factual about it, I would guess that PHP et al, use either the native MSSQL API or they use the standardized ODBC - warping around at the protocol level is just asking for it.

Related

Get Data From OPC-UA Server using C#, without GUI

We have a background service, which has the single purpose of getting recent data from a server.
Now the server should be an OPC-UA server. Unfortunaly, the SDKs and examples I found to connect to this are limited/only explained in ways that are heavily integrated with a classic windows forms application. Up to the point where its impossible to separate GUI from business logic.
At this point I'm wondering if we are misusing the client functionality and should opt for a different way?
Ideally I'd like to wrap the whole OPC-UA Logic inside a class library and just call GetData(), is that impossible?
You are probably referring to the "SDK" provided by the OPC Foundation - but you have not stated that explicitly in your question; in fact, you used the term "SDKs", in plural. There certainly are also commercial SDKs which might be better in this respect.
Here is one (QuickOPC), together with one-liner example of reading the OPC UA data: https://www.opclabs.com/products/quickopc/opc-specifications/unified-architecture/generic-data . Disclaimer: This is a self-promotion.
You might find Tutorials for Client development, specifically Console Client useful. This is a much better SDK than the one from the OPC Foundation. You will find full C# samples including a console client application (no GUI).
You might want to re-evalute your needs for
Ideally I'd like to wrap the whole OPC-UA Logic inside a class library and just call GetData(), is that impossible?
It is totally possible, but with OPC-UA, you have to keep in mind that it is recommended to get data using a subscription model (Monitored Items) instead of performing an explicit Read for a value (unless you just want to read an attribute once). So, I would make sure that however you are building your client-side class makes sense for the needs of your application.

(lightweight) Instant Messenger: C#.Mono, node.js or other?

Which programming language should I use to write an Instant Messenger?
Here are the goals:
should be able to handle many, many users (at least for proof of concept)
protocol should be based on json or maybe binary data. i guess json is easier to implement and extend. I don't want to use XML because of the overhead. I know it's not much data but it should be as fast as possible especially on slow networks (e.g. mobile).
users should be able to be logged in on multiple devices simultaneously
history should be saved server sided so it can be viewed on all devices
server should keep a lot of idle clients alive
file transfer (not quite sure on how to realize, maybe a different network socket so it does not block chat messages on client side)
MySQL auth
(No, XMPP is not an option).
I'm a web developer with good experience in PHP but that is not an option for this project. I also have experience with Javascript (mainly for websites), but it would be easy for me to work with node.js and I have little experience with C#.Net and could also write C#.Mono. The server I want to write should run on Linux. I have no experience with Java but if it's the best way I could learn it.
I've read much about node.js and that it's evented I/O is really good for network applications and web servers. But what about instant messengers? The main part is to save messages and proxy them to the other room participants, so it's "network".
I also thought about C# which offers asynchronous sockets which work with a thread pool afaik instead of a event queue.
I'm not sure which of them is most efficient in regard of an IM server.
It would be nice if someone could give me a hint. I know C++ would probably be the best way but I somehow don't really like that language and it's hard to learn.
You can do all this in any normal programming language (C#, Java, C++, etc...), as long as you're competent enough in that language.
Any of those solutions will do. You can write evented networking code in pretty much any language - and yes, it's pretty cool to use it in scenarios like this one.
If you want something that will give you some kind of framework for easier networking, I'd recommend trying Erlang, but it might be tough to learn for a single project. node.js might be tricky with regards to keepalives / resource management on dead connections and similar scenarios where you don't really get an event.
If you're already familiar with c#, using mono might be the safest / fastest thing for you. Apart from that - you can write anything in any language - just use what you're comfortable with (unless you actually want to learn something new).
I don't know why you wrote that jabber isn't an option, but if it's only the xmpp technology you don't want, why not use a typical SIP proxy/server? (for example OpenSIPS) It's got MESSAGE request handling, subscriptions, authorization (with db) and keepalives already available. You can scale / cluster / shard OpenSIPS in pretty much any way you want.

TCP/IP vs Web Services for iPhone chat app

How to create a NATIVE chat app for the iPhone? So far we have been exploring a few options:
Creating a web service using php or other web based language and have the app connect to that. Only problem is we can't figure out how to create "push" messaging with this, where the user will not have to refresh the conversation constantly.
Hosting an application on a server such as Windows Azure which will communicate to the iPhone app using TCP/IP. This way it seems like "push" messaging could be achieved by simply sending a packet to the iPhone. However, we have never done this before and don't know if we would run into any unforeseen potholes.
Have any of you made such an app before? If so how did you go about doing it? If not, what method would you recommend?
Thank you in advance!
EDIT:
To tell you exactly what we're trying to do: we need to make an app where a user can join a chat room and send/ receive messages from that chat room. There will also be custom features like that users will have their own profiles, etc. We would also like to make this as flexible as possible, so that we can integrate it on other platforms like android and blackberry later on.
So essentially the part that I'm stuck on is the send/ receive messages from a chat room. What technology should we use server side?
Something with an open socket, like Socket.IO could work. Node.js is a good server-side framework to explore. Here's an related SO question: iPhone Objective-C socket communication with Socket.IO
EDIT:
Question has changed since posting this answer -- originally question asked about web apps. ALso, originally the question was not clear that you wanted answers about the server side more than the client side.
On the server side, I would still recommend Node.js -- sounds like you want to use C# though, which makes me wonder why you're asking again about what server side tech to use. Most languages will provide you with ways to connect a socket to a client and access a database, which are the two main requirements of the app that it sounds like you want to make. Use whatever language you're comfortable with. However, some are going to come with libraries that may come in handy for this type of communication -- Node.js and Ruby on Rails (more useful if you want to do a polling-based solution)
Look at http://code.google.com/p/cocoaasyncsocket/ for a good library for doing socket communication from the iPhone without having to delve too deep into the low-level functions.
I've done this several times. Scaling to 100K concurrent users is non-trivial. If you want an off-the-shelf system I suspect ejabberd may do what you want. although the protocol IMHO is too verbose and uses far more bandwidth than necessary.
If you want to write your own solution and have the flexibility to write your own protocol and have the maximum possible scalability in the future then use a language that allows you to distribute the application across several servers. It is easier to allow that from the get go rather than writing a single server solution then have to retroactively make it distributable.
Having written servers like this in c++, Java and Erlang I would say the easiest and most relevant tool was Erlang. It makes good use of multi core processors and with a good design it facilitates distributing across several servers. C++ was the hardest!
I have also used Java with tools like JETTY and RabbitMQ to write a highly scalable system that required using HTTP as the protocol.
Personally I prefer a custom binary protocol as it allows you to reduce bandwidth to a minimum, and avoids DOS attacks and such as the protocol is well defined and lengths are sent before the packet, where as non binary protocols need to be parsed as they come in, with no idea of how big the packets may be.
Why not try XMPP protocol first? XMPP is based on TCP/IP.
There are several OpenSource server solution, clients, and application libraries. XMPP already supports chat room like service. You can define extension easily.

Correct way of implementing database access using .net remoting

Im looking to implement a .net remoting system, where a number of clients will need access to a server database. Client calls may be concurrent, but Im wanting to queue client requests to the database to avoid concurrent database access.
Im just learning .net remoting and have read about singlecall, singleton and client activated objects. Do any of these methods do what I want or at least support what I want?
Also, should I be using .net remoting or is the way to go WCF?
Kind Regards
Ash
You might want to look at creating a WCF Data Service. You should definitely look at this rather than Remoting.
In a nutshell, you can use it to expose an Entity Framework or Linq to SQL model as a Webservice. It's pretty neat!
Marc Gravell has a very good blog post on the topic: http://marcgravell.blogspot.com/2008/12/astoria-and-linq-to-sql-getting-started.html.
Update: I don't know if you can configure the data service itself to queue requests, but you might be able to achieve it by configuring IIS to queue the requests for you. There will probably be a web.config setting you can use to do it.
One request at a time is a bit of an odd requirement though... WCF Data Services do support optimistic concurrency, might that be better suited to your needs? Without more information on your requirements it's only a guess, but it's worth considering.
I'm not sure why you're trying to achieve one request at a time, but it's worth asking yourself if there's a better way of achieving your goal. Limiting database access to one user at a time seems very heavy handed to me.
.NET Remoting has been deprecated in favor of WCF. You should not be using it for any new development.

Cross-platform open-source asychronous HTTP and DB with C#

Does anyone know of a good resource for open-source libraries for asynchronous C# (or native stuff to the language). I'm interested in anything on this topic, but I'm specifically looking for stuff pertaining to HTTP and DB calls. Maybe an event-driven framework with plugs for HTTP and DB?
Unfortunately I can't use a non-C# solution or anything that does not work on mono, unless it is planned to run on mono soon.
For HTTP, it kinda depends on whether you're talking about client or server. Assuming client, you could just use the *Async methods in WebClient
http://www.go-mono.com/docs/index.aspx?link=T:System.Net.WebClient/*
For DB, the sqlcommand (or similar) class exposes BeginExecute* methods for async calls
http://www.go-mono.com/docs/index.aspx?link=T:System.Data.SqlClient.SqlCommand/*
You would probably have to use some kind of queue system. There are lots of queue engines. MSMQueue is the "standard" Microsoft solution.
Have you looked at the Linxter Internet Service Bus system? You can find some details at http://www.linxter.com and some sample apps that show how to perform database transactions distributed over the Internet.
The question is quite generic, both HTTP, DB and asynchronous could mean a lot of different things, depending on the requirements:
On codeplex you can find a more standards compliant HTTP server implementation which is event driven, compatible with Mono and has been used by others successfully.
There are a number of Asp.Net providers, as well as NHibernate
For Linq to Sql, your best option will probably be to use DbLinq although DbLinq is being included in the Mono namespace.
You probably should check NServiceBus. If it runs on mono it offers you a good framework for asynchronous calls (based on messaging).
It doesn't offer DB or HTTP connectivity by default, but this should be fairly easy to integrate.

Categories