Multiple SMPP connection threading example?

.NET library for SMPP protocol
Locked
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Multiple SMPP connection threading example?

Post by ishmell » Wed Jan 25, 2012 1:51 am

Hello everyone,

I'm an old VB6 programmer and I'm new to VB.NET and threading. I understand how to start threads, control threads, and even how to use the threadpool... what I don't really understand at this point is what the best approach is to create an SMPP client that can pull connection data for a number of SMSCs from a database and connect & bind to them all. I have 5 different SMPP connection partners (and growing), and I'd like to create a multithreaded windows service that will be able to manage connections to these SMSCs.

I started down the road of creating a separate thread for each SMSC and passing it a class object with connection details and properties, which would in turn create a new Inetlab.SMPP.SmppClient object, set properties, etc. - I didn't get very far. It's not clear to me how to keep each thread alive while doing things like binding and waiting for async calls like BindAsync to raise events. Here's how I'm looping through threads and passing them to the threadpool;

While oRS.Read()
oChannel = New classSMPPChannel 'create new class object
oChannel.ChannelID = oRS("ChannelID").ToString
Threading.ThreadPool.QueueUserWorkItem(AddressOf oChannel.Start, oChannel)
oChannel = Nothing 'kill class object
End While

The oChannel.Start sub creates the SmppClient object and tries to initiate a connection, but the thread dies after that. So, now I'm thinking I can create an array of SmppClient objects in the main service thread and manage them that way, however I don't know if this is ideal either. Even if I use the available async methods, it still doesn't feel like a very scalable solution.

Any suggestions would be greatly appreciated!
alt
Site Admin
Posts: 988
Joined: Tue Apr 25, 2006 9:45 am

Re: Multiple SMPP connection threading example?

Post by alt » Mon Jan 30, 2012 8:22 am

Hello ishmell,

I think you don't need to create additional threads. Use async methods. When windows service is started initialize all client instances, attach to events. On service stop wait when all clients are stoped using ManualResetEvent and event evDisconnected.
Locked