[Tutor] Socket programming

2015-01-03 Thread pramod gowda
Hi,

 i am learning socket programming,

client code:

import socket

client_socket=socket.socket()
server_address='192.168.2.2'
server_port= 80
print("hello")
client_socket.connect((server_address,server_port))
print("hello")
data=client_socket.recv(1024)
print(data)
client_socket.close()

server code:
import socket

server_socket=socket.socket()
server_name='192.168.2.2'
server_port= 80
server_socket.bind((server_name,server_port))
server_socket.listen(1) 3.4.2

while True:
print("hello")
c,address=server_socket.accept()
print("we got connection from:",address)
c.send("hello,hw ru")
c.close()




I am not getting the output, i am using windows 7 OS,pyhton ver:..
please  check and give me the solution.
Regards,

Pramod SP
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 131, Issue 14

2015-01-03 Thread pramod gowda
Hello ,


I have chaged the code as per your input, except port number.
If i change the port number it give me error as

Traceback (most recent call last):
  File "C:\Users\Pramod\Desktop\client.py", line 7, in 
client_socket.connect((server_address,server_port))
ConnectionRefusedError: [WinError 10061] No connection could be made
because the target machine actively refused it




Server code:

import socket

server_socket=socket.socket()
server_name='192.168.2.2'
server_port= 80
server_socket.bind((server_name,server_port))
server_socket.listen(5)

while True:
print("hello")
c,address=server_socket.accept()
print("acception the connection")
print("we got connection from:",address)
c.send("hello,hw ru")
c.close()

Client Code:

import socket

client_socket=socket.socket()
server_address='192.168.2.2'
server_port= 80
print("port number entered")
client_socket.connect((server_address,server_port))
print("it is connected")
data=client_socket.recv(1024)
print("received:",data)
client_socket.close()
print('finished')



Output :


port number entered
it is connected
received: *b''*
finished


In the above output expected data is 'hello,hw ru' from the server and
 print("acception the connection")
  print("we got connection from:",address)

the above print statements are not executed.

Thanks and Regards,
Pramod SP

Regards,

Pramod SP

On Sat, Jan 3, 2015 at 8:39 PM,  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>1. Re: Improving My Simple Game Code for Speed,  Memory and
>   Learning (Dave Angel)
>2. Socket programming (pramod gowda)
>3. Re: Socket programming (Alan Gauld)
>4. Re: Improving My Simple Game Code for Speed,  Memory and
>   Learning (Steven D'Aprano)
>
>
> --
>
> Message: 1
> Date: Sat, 03 Jan 2015 06:58:34 -0500
> From: Dave Angel 
> To: tutor@python.org
> Subject: Re: [Tutor] Improving My Simple Game Code for Speed,   Memory
> and Learning
> Message-ID: <54a7d96a.6040...@davea.name>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 01/02/2015 10:21 PM, Dave Angel wrote:
> > On 01/02/2015 09:00 PM, WolfRage wrote:
> >> Python3.4+ Linux Mint 17.1 but the code will be cross platform (Mobile,
> >> Windows, Linux, OSX).
> >>
> >> First an explanation of how the game works: The game is a simple
> >> matching game but with a twist. Instead of matching a straight 3 in a
> >> row, we have some rules that only certain combinations will result in an
> >> elimination. In general 2 of the same value in a row with with 1 of 2
> >> other possible values will eliminate all three nodes. Eliminations can
> >> occur either horizontally or vertically but not diagonally. Each tile
> >> has a value now, that value is used when evaluating the rules. Currently
> >> there are only 5 allowed values of 0-4 although more could be added
> >> later, so any solution needs to be expandable.
> >> These are the basic rules that allow for an elimination to occur(values
> >> are put in quotes to distinguish values):
> >> 2 "5"s followed or proceeded by a "19" will eliminate all 3 nodes.
> >> 2 "5"s followed or proceeded by an "11" will eliminate all 3 nodes.
> >> 2 "6"s followed or proceeded by a "5" will eliminate all 3 nodes.
> >> 2 "6"s followed or proceeded by a "19" will eliminate all 3 nodes.
> >> 2 "11"s followed or proceeded by a "6" will eliminate all 3 nodes.
> >> 2 "11"s followed or proceeded by a "20" will eliminate all 3 nodes.
> >> 2 "19"s followed or proceeded by a "20" will eliminate all 3 nodes.
> >> 2 "19"s followed or proceeded by an "11" will eliminate all 3 nodes.
> >> 2 "20"s followed or proceeded by a "6" will eliminate all 3 nodes.
> >> 2 "20"s followed or proceeded by a "5&