跳至主要内容

python socket

======server=======:

from socket import *

sock=socket(AF_INET, SOCK_STREAM)
sock.bind(('',12345))
sock.listen(5)
while True:
    c, addr=sock.accept()
    while True:
        try:
            data=c.recv(1024)
        except:
            print(e)
            c.close()
            break        if not data:
            break        c.send('backinfo'.encode('utf8'))
c.close()
sock.close()
======================


=========Client=============

from socket import *

c=socket(AF_INET, SOCK_STREAM)
c.connect(('127.0.0.1',12345))


c.send('hello from client'.encode('utf8'))
data=c.recv(1024)
if not data:
    passprint(data.decode('utf8'))

c.close()
===================================

评论

此博客中的热门博文

android hide actionbar

public class MainActivity extends Activity { ActionBar actionBar; //声明ActionBar @Override protected void onCreate( Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView( R .layout.activity_main); actionBar = getSupportActionBar(); //得 到ActionBar actionBar.hide(); //隐藏ActionBar } }

go url encoding

func  QueryUnescape func QueryUnescape (s string ) ( string , error ) QueryUnescape does the inverse transformation of QueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits. func  QueryUnescape func QueryUnescape (s string ) ( string , error ) QueryUnescape does the inverse transformation of QueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits.