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 1004935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:12:41+00:00 2026-05-16T08:12:41+00:00

I wrote two applictions which comunicate by socket. This is the code: Server: import

  • 0

I wrote two applictions which comunicate by socket. This is the code:

Server:

import socket

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(("",9999))
server_socket.listen(5)

video = True
power = True

print "TCPServer Waiting for client on port 9999"

while 1:
    client_socket,address = server_socket.accept()
    print "I got a connection from ", address

    while 1:
        data = client_socket.recv(512)
        if data == 'vc' & video == True:
            data = 'You can connect to Video'
            video = False
            client_socket.send(data)
        elif data == 'pc' & power == True:
            data = 'You can connect to Power Switch'
            power = False
            client_socket.send(data)
        else :
            data = 'Device is in use - wait a few secconds'
            client_socket.send(data)

Client:

import socket
import time
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("localhost", 9999))
while 1:
    data = ( 'Please vc or pc: ' )
    time.sleep(5)
    if data=='pc' | data=='vc':
        print 'send to server: ' + data
        time.sleep(5)
        client_socket.send(data)
        data = client_socket.recv(512)
        print data
    else:
        print 'bad data - please try again'

    print data
    time.sleep(5)

I’ve just started my adventure with sockets and I have a problem. Why I don’t see server response? I paste in code time.sleep() to stop the program and see rosponses, but those applications terminate after I wrote first message in client terminal and press enter. Please, help me.

I work on Windows 32bit. Python 2.6

  • 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-05-16T08:12:42+00:00Added an answer on May 16, 2026 at 8:12 am

    You don’t send anything. I presume the line data = "Please vc or pc: is meant to get input from the user, but it just assigns the string to data. Then when you check if data == 'pc' | data == 'vc' the check fails so it prints “bad data”.

    Also do not use | in boolean expressions – use or and and. | and & will do bitwise manipulation – sometimes that will do the right thing, but other times it will bite you in the butt.

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

Sidebar

Related Questions

I wrote two small applications (a client and a server) to test UDP communication
I wrote two code both are same Using NSURLConnection and Using AFNetworking. My NSURLConnection
I wrote two small java programs: a TCP client which sends many lines of
My client-server communication looks like this: there are some so called annoucements which are
I wrote two small C++ applications, one of which is an ActiveX container embedding
I have trouble with some code I just wrote. Basically, this code is inside
I have wrote an application that syncs two folders together. The problem with the
I wrote two methods with a void type parameter: procedure Method1(const MyVar; size: cardinal);
I wrote two methods in class Util: public static final <T> T[] copy1(T[] source)
I wrote two methods to check there performance public class Test1 { private String

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.