472,958 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 4312

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);...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.