Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83168
| 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 | <drsalists@gmail.com> |
| 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 | <f8631430-9364-42c8-8b12-daa3da4edf7c@googlegroups.com> |
| References | <f8631430-9364-42c8-8b12-daa3da4edf7c@googlegroups.com> |
| Date | Sat, 3 Jan 2015 09:16:57 -0800 |
| Subject | Re: Socket programming |
| From | Dan Stromberg <drsalists@gmail.com> |
| To | pramod gowda <pramod.sp78@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | Python List <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17352.1420305910.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Sat, Jan 3, 2015 at 3:43 AM, pramod gowda <pramod.sp78@gmail.com> 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 03:43 -0800
Re: Socket programming Chris Angelico <rosuav@gmail.com> - 2015-01-03 22:56 +1100
Re: Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 04:25 -0800
Re: Socket programming Chris Angelico <rosuav@gmail.com> - 2015-01-03 23:38 +1100
Re: Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 05:22 -0800
Re: Socket programming mm0fmf <none@mailinator.com> - 2015-01-03 15:09 +0000
Re: Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 07:15 -0800
Re: Socket programming Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-01-04 02:57 +1100
Re: Socket programming pramod gowda <pramod.sp78@gmail.com> - 2015-01-03 08:10 -0800
Re: Socket programming Dan Stromberg <drsalists@gmail.com> - 2015-01-03 09:16 -0800
Re: Socket programming Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-01-04 18:12 +0000
csiph-web