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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:41:32+00:00 2026-05-24T03:41:32+00:00

Edited Original question was about trouble with reconnecting (close() and shutdown() confusion). The below

  • 0

Edited

Original question was about trouble with reconnecting (close() and shutdown() confusion). The below code is the working code (fixed)
For Googler’s, this script is an IRC bot. Feature list:

  • Keep reconnecting until connection available
  • If assigned nick is already taken, puts string behind name (repeats until success)
  • Listens to PING and responds with PONG
  • Can listen to commands and respond
  • If connection is lost, the bot will try to reconnect (if no information is received, no PING, in 5 mins, it treats the connection as if it was disconnected)

That is about it 🙂

Full Code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import socket
import string
import os
import platform
import time

# Variables
HOST = "irc.server.net"
PORT = 6667
NICK = "Nickname"
IDENT = "Nickname"
REALNAME = os.getenv('USER')
CHAN = "##Channel"
readbuffer = ""

# The Connection itself
keep_connecting = True
while keep_connecting:
    irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    irc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    irc.settimeout(300)
    try:
        irc.connect((HOST, PORT))
        pass
    except socket.gaierror:
        print "No connection, attempting to connect again"
        time.sleep(5)
        continue
    print "Sending info..."
    irc.send("NICK %s\r\n" % NICK)
    irc.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
    irc.send("JOIN :%s\r\n" % CHAN)
    # Initial msg to send when bot connects
    irc.send("PRIVMSG %s :%s\r\n" % (CHAN, "TehBot: "+ NICK + " Realname: " + REALNAME + " ."))
    while True:
        try:
            data = irc.recv(4096)
            print data
            # If disconneted from IRC
            if len(data) == 0:
                print "Length of data == 0 ?..."
                break
            # If Nick is in use
            if data.find (NICK + " :Nickname is already in use") != -1:
                NICK = NICK + str(time.time())[5:-3]
                break
            # Ping Pong so we don't get disconnected
            if data[0:4] == "PING":
                irc.send ("PONG " + data.split() [ 1 ] + "\r\n")
        except socket.timeout:
            print "Socket timeout!"
            irc.close()
            break
  • 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-24T03:41:33+00:00Added an answer on May 24, 2026 at 3:41 am

    This is most probably because you’re switching off wi-fi and the interface is removed from system so you get something like Can’t assign requested address. You would get such an error while trying to bind to non-existing local address.

    The other thing is you won’t be able to reconnect on the same socket after calling close as it releases all resources associated to the socket.

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

Sidebar

Related Questions

[EDITED: I left the original question below, with some more context and code to
This question has been edited to ask about a specific example as the original
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Ok, i kind of asked the wrong question so I've edited the original question.
I edited my original text to demostrate my entire set of code for those
I have edited the original question since the same error is occurring the difference
Note: I edited this question to make it easier for other people with the
In response to the helpful comments, I have edited the original question (where I
EDITED WITH NEW CODE BELOW I'm relatively newbie on Multithreading but to achieve my
(EDITED) In original question I erroneously assumed that GridView natively use 2-dimensional model. Indeed,

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.