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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:11:52+00:00 2026-06-18T12:11:52+00:00

I am trying to use an example for a server, but the client can

  • 0

I am trying to use an example for a server, but the client can only send one message and then the server will reply with a number.

Here is the code.

import socket
mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
mySocket.bind ( ( '', 2000 ) )
mySocket.listen ( 1 )
while True:
   channel, details = mySocket.accept()
   print 'We have opened a connection with', details
   print channel.recv ( 100 )
   channel.send ( 'Green-eyed monster.' )
   channel.close()

Questions:

  1. Why is it that whenever the client sends a message to the server, it responds with a number?

  2. How can I use sockets over the Internet, not over LAN?

  3. Is there a way for me to have the server move data from client to client using sockets – somewhat like an IM program.

  4. I will most likely host this IM server for my friends on my Mac – will it work between OS’s (Mac, PC)

  5. Are there any good libraries to use for this? (I have heard that HTTP is great)

  6. These lines of code are really confusing. How do they work?

    print channel.recv ( 100 )
    channel.send ( 'Green-eyed monster.' )
    
  7. Also, when I close the server (using the red X), and reuse the port, it says this:

    Traceback (most recent call last):
    File "C:\Users\****\Desktop\Python\Sockets\First Server\server.py",
    line 3, in <module>
    mySocket.bind ( ( '', 2003 ) )
    File "C:\Python27\lib\socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
    error: [Errno 10048] Only one usage of each socket address
    (protocol/network address/port) is normally permitted
    
  8. Lastly, where are some good tutorials for me to understand this better?

Sorry for asking so many questions in the same post, but when I posted this and this people got mad with me for posting about similar problems in different problems.

Python version: Python 2.7.3

  • 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-18T12:11:53+00:00Added an answer on June 18, 2026 at 12:11 pm

    I have done some research (over several hours) and have found some solutions to my issues!

    3: Yes, There is a way to have the clients communicate with each other, they just have to use the server! You have to initialize an infinite loop on the server side, which will receive data and send it. This is how I solved the issue:

        while True:
            #Receiving from client
            data = conn.recv(1024)
            if not data:
                break
            conn.sendall(data)
            print data
            #To come out of the loop
        conn.close()
    

    This program is part of a definition called clientthread which initializes all connections with clients. The “Actual” loop carries on the rest of the thread:

         while True:
            #Wait to accept a connection - blocking call
            conn, addr = s.accept()
            #display client information (IP address)
            print 'Connected with ' + addr[0] + ':' + str(addr[1])
    
            #Start new thread takees 1st argument as a function name to be run, second
            #is the tuple of arguments to the function
    
            start_new_thread(clientthread ,(conn,))
    

    4: Yes, it will work between OS’s. Sockets are independent of the platform.

    6: That line of code is actually quite simple. The line print channel.recv ( 100 ) tells the server to print the user input, up to 100 characters. The next line, channel.send ( 'Green-eyed monster.' ) is simply telling the server to send out a message, Green-eyed monster to the client.

    7: That error occurs because you cannot have more than one socket open per port. I would suggest using a line such as s.close() or sys.exit() at the end of your code, to close the port. Or you can simply choose another one!

    8: There are some great tutorials out on the internet. One that teaches you the basics of sockets is this. Telnet was really confusing for me, so I discovered that in conjunction with this client one can create a customized client which is in fact much better.

    If you have any questions, feel free to comment and I will try to answer.

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

Sidebar

Related Questions

I'm trying to use an SSL client/server example from: http://simplestcodings.blogspot.com.br/2010/08/secure-server-client-using-openssl-in-c.html to create a secure
I'm trying to use the example that comes in the slony tutorial but it
Trying to use the following demo example, using the 80px x 80px snap to
I am trying to use session data on multiple subdomains: www.example.com my.example.com test.example.com whateversub.example.com
I am trying to use the Microsoft Kinect SDK SlideShow example as the basis
trying to use regex to replace any white space with &nbsp;, inside of example
I'm trying to use ftp_connect('ftp.is.co.za') [for example] in PHP 5 or higher (multiple different
I am trying to use Astyanax for Cassandra with Java. I tried the example
I am trying to use Class::DBI with Catalyst::Plugin::Authentication::Store::DBIC. The example given on CPAN does
I am trying to use dynamically created list in WHERE, for example: select *

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.