1

I am using chilkat socket class. The problem is I want to keep my socket open, lets say I executed my form and the very first time which opened the port on a specific IP to listen the messages.I am able to receive the messages first time only successfully, now after this message I want to keep my application to keep listening and receive when ever a new message comes.

We have several clients who will connect and send some text messages on the same port and ip.

But I am unable to achieve this. I need to build a Listener, which will keep on listening and as soon as I will get any message I need to process it. Any body who has used chilkat class or having experience in this kind of application kindly suggest me how can I achieve this functionality as I could't find good example for this kind of application on CHILKAT website or may be I am inexperienced don't know how to exactly code this type of functionality.

Edit 1: Jermy,

yes we have developed REST WCF services and they are working perfect, but the problem is in the response of REST WCF Service big response headers are appearing, which we don't want because in our enterprise application Windows Phone 7 mobiles will also communicate and send text messages and only for the sake of mobiles we are trying to reduce the data we need to pass back and by using sockets we can avoid extra response headers and SMS is not an option for us because of cost. If you have any suggestions towards Webservices to minimize the data kindly share it.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Shax
  • 4,207
  • 10
  • 46
  • 62
  • Any special purpose to use `Chilkat` instead of classes in `System.Net` and `System.Net.Sockets` ? – L.B Nov 07 '11 at 20:39
  • L.B, because we are using currently chilkat in other parts of our application for crypto stuff and due to its simplicity we opted to go for chilkat. But it looks like that chilkat socket might not be the perfect option in our scenario or may be I am not able to utilize it properly. – Shax Nov 07 '11 at 21:45
  • Restful services don't have the soap headers weighing you down so I guess sockets is an option. Check my edit. – Jeremy Nov 07 '11 at 21:56
  • 1
    @Shax `may be I am not able to utilize it properly` This is the most probable case. But you have more chance in getting help with windows sockets. – L.B Nov 07 '11 at 22:03
  • @JeremyChild, you said check my edit. Where is your edit or what you edited could't find your edit Jeremy. – Shax Nov 07 '11 at 22:07
  • @Shax my boss was over my shoulder, had to wait for the opportune time. – Jeremy Nov 07 '11 at 22:19
  • @Shax I will just obfuscate some code I have here that is a little old but does what I'm talking about. – Jeremy Nov 07 '11 at 22:49

1 Answers1

0

Have you considered a Web Service? They can be consumed by pretty much any language that can send Http requests. If you have control of the client applications then a Web Service is definitely the correct route.

http://sarangasl.blogspot.com/2010/09/create-simple-web-service-in-visual.html

Edit:

Have you considered simple http upload of bytes, with a http response code. Ie Http Ok, Http Failure. You can customize the status codes to anything that suits your project.

Edit 2:

Perhaps an RPC styled method with ONLY http status codes as the response could be suitable. Checks this question for hints. json call with C#

Basically you are just sending some string to a url, then receiving the status code back. That is quite minimal.

Edit 3:

Here is something I pulled out of some old code with Reflector. This is just for the general gist of the procedure. Obviously there should be a using statement on the first request.

public void SMS(Uri address, string data)
{

   // Perhaps string data is JSON, or perhaps its something delimited who knows.
   // Json seems to be the pretty lean.
    try
    {
        HttpWebRequest request = (HttpWebRequest) WebRequest.Create(address);
        request.Method = "POST";
        // If we don't setup proxy information then IE has to resolve its current settings
        // and adds 500+ms to the request time.
        request.Proxy = new WebProxy();
        request.Proxy.IsBypassed(address);
        request.ContentType = "application/json;charset=utf-8";
        // If your only sending two bits of data why not add custom headers?
        // If you only send headers, no need for the StreamWriter.
        // request.Headers.Add("SMS-Sender","234234223");
        // request.Headers.Add("SMS-Body","Hey mom I'm keen for dinner tonight :D");
        request.Headers.Add("X-Requested-With", "XMLHttpRequest");
        StreamWriter writer = new StreamWriter(request.GetRequestStream());
        writer.WriteLine(data);
        writer.Close();
        using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
        {
            using (Stream stream = response.GetResponseStream())
            {
                // Either read the stream or get the status code and description.
                // Perhaps you won't even bother reading the response stream or the code 
                // and assume success if no HTTP error status causes an exception.
            }
        }
    }
    catch (WebException exception)
    {
        if (exception.Status == WebExceptionStatus.ProtocolError)
        {
            // Something,perhaps a HTTP error is used for a failed SMS?
        }
    }
}

Remember to respond only with Http status codes and descriptions. And ensure that the request's proxy is setup to bypass the requesting Url to save time resolving the IE proxy.

Community
  • 1
  • 1
Jeremy
  • 3,880
  • 3
  • 35
  • 42
  • Jermy, kindly check the Edit 1 of orignal post, i appended for you. – Shax Nov 07 '11 at 21:46
  • No I could't tried honestly I am not aware of that. Could you guide me good tutorial for that where I can use HTTP upload and get a response as minimum as possible. – Shax Nov 07 '11 at 22:35
  • Jeremy thanks for the answer, I got the idea now I am going to fix it. – Shax Nov 07 '11 at 22:58