Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'socket': 0.07; 'skip:# 30': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'cc:name:python list': 0.16; 'chunks': 0.16; 'client:': 0.16; 'crlf': 0.16; 'server:': 0.16; 'subject:programming': 0.16; 'true:': 0.16; 'sat,': 0.16; 'skip:# 20': 0.16; 'wrote:': 0.18; 'pfxlen:0': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'bytes': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; 'this.': 0.32; 'linux': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'connection': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'programming,': 0.36; 'url:org': 0.36; 'should': 0.36; 'two': 0.37; 'others.': 0.38; 'skip:c 50': 0.60; 'simple': 0.61; 'to:addr:gmail.com': 0.65; '2015': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=C8jZUGd9njYlYGpIZLsLnzSHBCetbJOBtZp+uAfqapQ=; b=LbWATYp0gvFf3Jg1k5ByM66zqWH6vKxNuLpi6+xgWdrMpMufv2Qdr+fUxh0yxxMvox 4dZQEMob75zlf+9MXD+VihTTnr19K3T0KitBml8E4/O/RC2WUoYvrwwWhY+D8GgWrOnh iwx5z6KF7iynytzrBhiyegeRME8mtTqeyIOzwApGdepJxUkwMO40yLrPHtF7zX7lzOwr topgXGj2IPFs7wDV56QTb5nlzceWC12/vkzlJkXLF//YK4ayIwQvD/3M9v0mCnS6zvg7 hAetwoznNPbgt0ZyMum2Kx73eVfXIYLqe7G3GAPzg8f+8t0DwQqb8pZa2XxuOCrLbz3K 8YWQ== MIME-Version: 1.0 X-Received: by 10.152.6.132 with SMTP id b4mr63940240laa.59.1420305417791; Sat, 03 Jan 2015 09:16:57 -0800 (PST) In-Reply-To: References: Date: Sat, 3 Jan 2015 09:16:57 -0800 Subject: Re: Socket programming From: Dan Stromberg To: pramod gowda Content-Type: text/plain; charset=UTF-8 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420305910 news.xs4all.nl 2961 [2001:888:2000:d::a6]:35035 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83168 On Sat, Jan 3, 2015 at 3:43 AM, pramod gowda wrote: > Hi i am learning socket programming, This "works" on Linux Mint 17.1. Server: #!/usr/local/cpython-3.4/bin/python import socket server_socket = socket.socket() #server_name = '192.168.2.2' server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server_name = 'localhost' server_port = 8080 server_socket.bind((server_name, server_port)) server_socket.listen(1) while True: print("hello") c,address = server_socket.accept() print("we got connection from:",address) c.send(b"hello,hw ru") c.close() client: #!/usr/local/cpython-3.4/bin/python import socket client_socket = socket.socket() #server_address='192.168.2.2' server_address = 'localhost' server_port = 8080 print("hello") client_socket.connect((server_address,server_port)) print("hello") data=client_socket.recv(1024) print(data) client_socket.close() But note that if you send 10 bytes into a socket, it could be received as two chunks of 5, or other strangeness. So you should frame your data somehow - adding crlf to the end of your send's is one simple way. There are multiple ways of dealing with this. Here's one: http://stromberg.dnsalias.org/~strombrg/bufsock.html with links to others.