Answers for "python create socket server"

6

send data through tcp sockets python

import socket
TCP_IP = '127.0.0.1'
TCP_PORT = 5005
BUFFER_SIZE = 1024
MESSAGE = "Hello, World!"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()
print "received data:", data
Posted by: Guest on April-30-2020
1

python3 socket server

import socket
import os

sock_file = "/tmp/python_socket"

if os.path.exists(sock_file):
    os.remove(sock_file)

sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.bind(sock_file)
sock.listen()
print("Listening...")
while True:
    conn, _addr = sock.accept()
    datagram = conn.recv(1024)
    request = datagram.decode('utf-8')
    conn.send(str("Back at you:"+request).encode('utf-8'))
Posted by: Guest on February-17-2021
-2

client server python socket

s = socket.socket (socket_family, socket_type, protocol=0)
Posted by: Guest on December-15-2020

Python Answers by Framework

Browse Popular Code Answers by Language