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

  • SEARCH
  • Home
  • 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 7873379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:29:48+00:00 2026-06-03T02:29:48+00:00

I am setting up a socket with TCP/IP-protocol, and since my receiver is handling

  • 0

I am setting up a socket with TCP/IP-protocol, and since my receiver is handling int8u_t i would like to know if this approach is correct.

At connection the server has to send a value mode=int(42) to the receiver which is done in def connectionMade(self). But i understand there will be some conflicts since the normal int in python is 32-bit and my receiver is only 8-bit, can i somehow cast it or create it in int8u?

from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor

class TestSocket(Protocol):
        def connectionMade(self):
                mode=int(42)
                self.factory.clients.append(self)
                self.transport.write(mode)
                print "clients are ", self.factory.clients

        def connectionLost(self, reason):
            self.factory.clients.remove(self)

        def dataReceived(self, data):
                #print "data is ", data
                #a = data.split(':')
                print data
                print "-------------------"

        def message(self, message):
                self.transport.write(message + '\n')

factory = Factory()
factory.protocol = TestSocket()
factory.clients = []

reactor.listenTCP(30002, factory)
print "TestSocket server started"
reactor.run()
  • 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-03T02:29:50+00:00Added an answer on June 3, 2026 at 2:29 am

    Use struct

    from struct import *
    mode = pack("h", 42) # 'h' == short
    

    edit: Apparently you wanted pack("I", 42)

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

Sidebar

Related Questions

How to increase the TCP receive window for a specific socket? - I know
Does setting this value have the same effect as setting the debug=true in the
I am working on a server application which receives data over a TCP socket
any help would be appreciated. Im developing a udp connection and i have a
I'd like to know how to communicate between processes on a Heroku worker dyno.
I created a server socket on my side. I don't know when client connects
I'm trying to lower the send buffer size on my non-blocking TCP socket so
The setting: I want to write a point-to-point Connection class that, when used, does
I'm having an issue with a socket programming job. I wrote a TCP client
I wanted to know how to flush the socket streams while doing socket programming

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.