Re: TCP sockets python timeout public IP adresss

2015-03-29 Thread bobbdeep
Changed server code to the following,

from socket import *

HOST = ''
PORT = 8080
serversocket = socket(AF_INET,SOCK_STREAM)
serversocket.bind((HOST,PORT))
serversocket.listen(5)
while True:
(clientsocket, address) = serversocket.accept()
print ("Got client request from",address)
clientsocket.send("Thank You for connecting")
clientsocket.close()



Still getting same error.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TCP sockets python timeout public IP adresss

2015-03-29 Thread bobbdeep
On Sunday, March 29, 2015 at 3:44:43 PM UTC+5:30, mm0fmf wrote:
> On 29/03/2015 09:57, bobbydeep wrote:
> 
>  From the error (10060) it looks like Windows but it would be nice if 
> you could say which Python and OS you were using.
> 
> I haven't looked at your code but just taking at face value that it does 
> work internally.
> 
> > server_address = ('my-server-ipadress', 1999)
> 
> Next thing to check is whether you have permission to open arbitrary 
> ports on the server and whether they are firewalled off. For example, I 
> have a shell account on the server that hosts my webpages and I can run 
> ftp / scp to move files across the internet. However, I cannot open say 
> port 54321 to the internet and accept connections on it.

I am using windows 8 and python 2.7.7. I did an nmap to my server to identify 
the list of open ports on my server. I found out that only three ports are 
open. How do I add a port to the list of open ports on my server ?
server version:
Linux hostname 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015 
x86_64 x86_64 x86_64 GNU/Linux
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TCP sockets python timeout public IP adresss

2015-03-30 Thread bobbdeep
On Sunday, March 29, 2015 at 2:27:59 PM UTC+5:30, bobbdeep wrote:
> I am trying to communicate between a server and client using TCP sockets. 
> 
> Server code:
> 
> import socket
> import sys
> 
> # Create a TCP/IP socket
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> # Bind the socket to the port
> server_address = ('my-server-ipadress', 1999)
> print >>sys.stderr, 'starting up on %s port %s' % server_address
> sock.bind(server_address)
> sock.listen(1)
>  try:
> print >>sys.stderr, 'connection from', client_address
> 
> # Receive the data in small chunks and retransmit it
> while True:
> data = connection.recv(16)
> print >>sys.stderr, 'received "%s"' % data
> if data:
> print >>sys.stderr, 'sending data back to the client'
> connection.sendall(data)
> else:
> print >>sys.stderr, 'no more data from', client_address
> break
> 
> finally:
> # Clean up the connection
> connection.close()
> 
> Client code:
> 
> from socket import *
> 
> clientsocket = socket(AF_INET,SOCK_STREAM)
> 
> clientsocket.connect(("my-server-ip-address",1999))
> 
> recv = clientsocket.recv(1024)
> 
> print(recv)
> 
> It is working fine on a local connection. The problem I am facing is when I 
> run the client code on my laptop (using my home wifi network)and try to 
> communicate with the remote server, it is not able connect to the server. 
> What could be the problem ? Any changes in the code required, or do I need to 
> disable firewall on my laptop ?
> 
> The error I get is, error: [Errno 10060] A connection attempt failed because 
> the connected party did not properly respond after a period of time, or 
> established connection failed because connected host has failed to respond

Thanks guys everything worksfine.
-- 
https://mail.python.org/mailman/listinfo/python-list


Communicating with multiple clients using one TCP socket pyt

2015-03-30 Thread bobbdeep
I am using TCP sockets to communicate between my server and clients. The server 
code and socket code are as below:

server:

from socket import *

HOST = 'xx.xx.xx.xx'
PORT = 1999
serversocket = socket(AF_INET,SOCK_STREAM)
serversocket.bind((HOST,PORT))
print 'bind success'
serversocket.listen(5)
print 'listening'
while True:
(clientsocket, address) = serversocket.accept()
print ("Got client request from",address)
#clientsocket.send('True')
data = clientsocket.recv(1024)
print data
clientsocket.send('True')
clientsocket.close()


client:

import socket
import sys

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Connect the socket to the port on the server given by the caller
server_address = ('xx.xx.xx.xx', 1999)
print >>sys.stderr, 'connecting to %s port %s' % server_address
sock.connect(server_address)

try:

message = 'This is the message.  It will be repeated.'
print >>sys.stderr, 'sending' 
for x in range (0,1):
  name=raw_input ('what is ur name')
  print type(name)
  sock.send(name)
  print sock.recv(1024)

finally:
sock.close()


I am able to communicate with the server from client and able to send and 
receive data. But the problem I am facing is that I am not able to send and 
receive data continuously from the server. I have to restart my client code on 
my laptop to send and receive data again from the server. The way the above 
client code is working is that when I give a keyboard input, then the socket 
sends data to server and server responds back. But in the client code, in the 
for loop if I do two iterations, for the second iteration the data I enter from 
keyboard is not reaching server. I need to restart my client code to send data 
again. How do I fix this ?

Also, when once client is connected to the server, the other cannot connect to 
the server. Any ideas on how to do this ?
-- 
https://mail.python.org/mailman/listinfo/python-list