Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8370129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:50:21+00:00 2026-06-09T13:50:21+00:00

I have a server where I have implemented a child of the NetstringReceiver protocol.

  • 0

I have a server where I have implemented a child of the NetstringReceiver protocol. I want it to perform an asynchronous operation (using txredisapi) based on the client’s request and then respond with the results of the operation. A generalization of my code:

class MyProtocol(NetstringReceiver):
  def stringReceived(self, request):
    d = async_function_that_returns_deferred(request)
    d.addCallback(self.respond)
    # self.sendString(myString)

  def respond(self, result_of_async_function):
    self.sendString(result_of_async_function)

In the above code, the client connecting to my server does not get a response. However, it does get myString if I uncomment

# self.sendString(myString)

I also know that result_of_async_function is a non-empty string because I print it to stdout .

What can I do that will allow me to respond to the client with the result of the asynchronous function?

Update: Runnable source code

from twisted.internet import reactor, defer, protocol
from twisted.protocols.basic import NetstringReceiver
from twisted.internet.task import deferLater

def f():
  return "RESPONSE"

class MyProtocol(NetstringReceiver):
  def stringReceived(self, _):
    d = deferLater(reactor, 5, f)
    d.addCallback(self.reply)
    # self.sendString(str(f())) # Note that this DOES send the string.

  def reply(self, response):
    self.sendString(str(response)) # Why does this not send the string and how to fix?

class MyFactory(protocol.ServerFactory):
  protocol = MyProtocol

def main():
  factory = MyFactory()
  from twisted.internet import reactor
  port = reactor.listenTCP(8888, factory, )
  print 'Serving on %s' % port.getHost()
  reactor.run()

if __name__ == "__main__":
  main()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:50:22+00:00Added an answer on June 9, 2026 at 1:50 pm

    There’s one specific feature about NetstringReceiver:

    The connection is lost if an illegal message is received

    Are you sure that your messages conform djb’s Netstring protocol?

    Obviously the client sends illegal string that could not be parsed, and connection is lost by protocol conditions. Everything else looks good in your code.

    If you don’t need that specific protcol, you’d better inherit LineReceiver instead of NetstringReceiver.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a web service with server and client authentication using keytool. The
I have a server implemented using Apache HTTPCore which can accept posts from an
I have a server and a client application, here's how it's currently implemented: The
I have a network server that was implemented using Jboss Netty. It servers the
I have a client server based windows forms application that needs an administrator only
We have a http server which is implemented based on Java NIO. It is
I have to connect to a poorly implemented server that only understands Content-Type (capital-T)
I have successfully implemented a mysql server as a JDBCRealm for authentication in Tomcat
I have written several procedures and succesfully implemented them on my webhost's server. However
I have a client-server Silverlight application, which is use Socets. I have server appliaction

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.