473,418 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Socket Error 106: 'Transport endpoint is already connected'

I am trying to write a simple FTP server in order to learn about
sockets
This is my first time trying sockets

This code should take a connection on port 8110, dump it to a client
"thread" (not a thread yet), print "Test\n" to the thread, and close
everything.
It fails on creating the client thread with error 106: 'Transport
endpoint is already connected'

On running the code:
dftp starting
getting the socket at 127.0.0.1 at port 8110
listening for 5 connections
entering main loop
####pause here until telnet####
found a client @ <socket._socketobject object at 0x2ba16f6cd650addr:
('127.0.0.1', 58643)
Creating a new client socket
Trying to connect
Traceback (most recent call last):
File "./dftpd.py", line 46, in ?
main()
File "./dftpd.py", line 41, in main
clientThread = Connection(clientsocket, address);
File "/home/palmer/prog/dftp/dftpd/connection.py", line 29, in
__init__
self.sock.connect(a);
File "<string>", line 1, in connect
socket.error: (106, 'Transport endpoint is already connected')

Telnet output:
$ telnet localhost 8110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

Here's my code:
config is a stand-in for a config-file reader, now it just runs
localhost:8110 and 5 connections
debug just prints to standard out (the number afterwords is the level,
but now everything is printed)
#################dftpd.py#########################
import debug
import socket
import config
from connection import Connection

shouldRun=True;

def main():
debug.stdout("dftp starting", 1)
debug.stdout("getting the socket at " + str(config.listenAddress()) +
" at port " + str(config.listenPort()), 10);
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
sock.bind((config.listenAddress(), config.listenPort()));
debug.stdout("listening for " + str(config.listenConnections()) + "
connections", 10);
sock.listen(config.listenConnections());
debug.stdout("entering main loop", 10);
while shouldRun:
(clientsocket, address) = sock.accept();
debug.stdout("found a client @ " + str(clientsocket) + " addr: " +
str(address), 10);
clientThread = Connection(clientsocket, address);
print clientThread.write("Test\n");
clientThread.close;
sock.close();

main()

########################connection.py############# ###########
import debug;
import socket;

class Connection:
def __init__(self, s, a):
debug.stdout("Creating a new client socket", 15);
self.sock = s;
debug.stdout("Trying to connect", 15);
self.sock.connect(a);
debug.stdout("Making the file over the socket", 15);
self.file = self.sock.makefile();
def read():
return file.read();
def write(out):
file.write(out);
def close():
file.close();
sock.close();

Jan 18 '07 #1
0 4527

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chuck E. Cheese | last post by:
I need a php page to connect to a python created socket and sent and receive data. below is the python code which opens a socket on the localhost @ port 21567: #!/usr/bin/python2 from socket...
1
by: Helge Aksdal | last post by:
i've recently made my very first socket program in python, however i've stumbled upon a problem. this program connects to a server serveral hundred time while it's executed (it's not possible to...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
2
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job...
6
by: J Rice | last post by:
Hi, I feel like I should apologize in advance because I must be missing something fairly basic and fundamental here. I don't have a book on Python network programming (yet) and I haven't been able...
0
by: mumebuhi | last post by:
I removed my previous post about this topic because I apparently have pasted the wrong code. Sorry for the confusion and thanks for being patient. I am having problem to kill the following...
3
by: Jason Kristoff | last post by:
I'm trying to make something that once it is disconnected will automatically try to reconnect. I'll add some more features in later so it doesn't hammer the server but right now I just want to...
3
by: A. W. Dunstan | last post by:
I'm creating a socket as follows: m_networkSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_networkSocket.LingerState = new LingerOption(true, 1);...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.