2 socket UDP通信
1 socket套接字 class 对象
In [1]: import socket In [2]: help(socket.socket)
class socket(_socket.socket)
| A subclass of _socket.socket adding the makefile() method.
|
| Method resolution order:
| socket
| _socket.socket
| builtins.object
|
| Methods defined here:
|
| __enter__(self)
|
| __exit__(self, *args)
|
| __getstate__(self)
2.socket通信udp
from socket import * udp_socket = socket(AF_INET,SOCK_DGRAM) udp_socket.sendto("haha",("192.168.123.1",8080))
3.端口的问题
#-*- coding:utf-8 -*-
from socket import * udp_socket = socket(AF_INET,SOCK_DGRAM) udp_socket.sendto("haha",("192.168.123.1",8080)) #使用upd发送的数据,在每一次都要写上接收方的ip和port
udp_socket.sendto("haha",("192.168.123.1",8080))
2)绑定端口号
#-*- coding:utf-8 -*-
from socket import * udp_socket = socket(AF_INET,SOCK_DGRAM) udp_socket.bind(("",8888)) udp_socket.sendto("haha",("192.168.123.1",8080))
4.接受数据
- 接收方需要绑定端口
- 发送方不需要绑定
#-*- coding:utf-8 -*-
from socket import * udp_socket = socket(AF_INET,SOCK_DGRAM) udp_socket.bind(("",7777)) recv_data = udp_socket.recvfrom(1024) #套接字接受数据
print(recv_data)
5.upd网路通信过程
2 socket UDP通信的更多相关文章
- bs结构socket(udp)通信
以前我所做的基于socket通信都是采用cs结构,现公司有一个项目需要在bs中反控设备,于是研究了一番,现将成果公布,方便以后查阅. 服务端: #region udp int recv; byte[] ...
- 【RL-TCPnet网络教程】第17章 RL-TCPnet之UDP通信
第17章 RL-TCPnet之UDP通信 本章节为大家讲解RL-TCPnet的UDP通信实现,学习本章节前,务必要优先学习第16章UDP用户数据报协议基础知识.有了这些基础知识之后,再搞本章 ...
- 重新想象 Windows 8 Store Apps (62) - 通信: Socket TCP, Socket UDP
[源码下载] 重新想象 Windows 8 Store Apps (62) - 通信: Socket TCP, Socket UDP 作者:webabcd 介绍重新想象 Windows 8 Store ...
- 与众不同 windows phone (31) - Communication(通信)之基于 Socket UDP 开发一个多人聊天室
原文:与众不同 windows phone (31) - Communication(通信)之基于 Socket UDP 开发一个多人聊天室 [索引页][源码下载] 与众不同 windows phon ...
- C语言socket编程----实现UDP通信
TCP/IP协议叫做传输控制/网际协议,又叫做网络通信协议.实际上,它包括上百个功能的协议. 套接字(socket):在网络中用来描述计算机中不同程序与其他计算程序的通信方式. 套接字分为三类; 流式 ...
- VC++使用socket进行TCP、UDP通信实例总结
1. 两台计算机通信需要协议,通信的两台计算机IP必须唯一 2. 同一个计算机可以进行多个应用程序与其他计算机通信,IP地址唯一,而端口号是区别同一计算机(同一IP)的唯一 ...
- Python的网络编程[0] -> socket[2] -> 利用 socket 建立 TCP/UDP 通信
Socket 目录 socket 的 TCP/IP 通信基本建立过程 socket 的 UDP 通信基本建立过程 socket 的 UDP 广播式通信基本建立过程 socket 的多线程通信建立过程 ...
- Python基于socket模块实现UDP通信功能示例
Python基于socket模块实现UDP通信功能示例 本文实例讲述了Python基于socket模块实现UDP通信功能.分享给大家供大家参考,具体如下: 一 代码 1.接收端 import ...
- UNIX下socket通信 - UDP通信
一.UNIX下socket通信: socket套接字是一种可以进行网络通信的内核对象,它是一个唯一的标示符,一般称它为socket描述符. 注意:UDP通信需要客户端先发送消息,服务端先进行等待客户端 ...
随机推荐
- git 和 github的学习
第一部分:我的github地址 https://github.com/Ly1235/gitLeaming 第二部分:git 和 github Git是一款免费.开源的分布式版本控制系统.gitHub是 ...
- *92. Reverse Linked List II (follow up questions)
Reverse a linked list from position m to n. Do it in one-pass and in-place Note: 1 ≤ m ≤ n ≤ length ...
- L2范数惩罚项,高维线性回归
%matplotlib inline import mxnet from mxnet import nd,autograd from mxnet import gluon,init from mxne ...
- SpringMVC学习记录七——sjon数据交互和拦截器
21 json数据交互 21.1 为什么要进行json数据交互 json数据格式在接口调用中.html页面中较常用,json格式比较简单,解析还比较方便. 比如:webservi ...
- java读取资源文件(Properties)
四步: java代码 //new一个读取配置文件 Properties properties=new Properties(); //获取文件路径 String path=request.getSer ...
- 宠物商城后台管理系统(springMVC+Mybatis+数据库)
mysql数据库 create database swager; use swager; #类别 create table Category( id int primary key auto_incr ...
- 【luogu P1456 Monkey King】 题解
题目链接:https://www.luogu.org/problemnew/show/P1456 左偏树并查集不加路径压缩吧... #include <cstdio> #include & ...
- 复合词(Compound Words, UVa 10391)(stl set)
You are to find all the two-word compound words in a dictionary. A two-word compound word is a word i ...
- An error occurred during the installation of assembly 'Microsoft.VC90.ATL or 'Microsoft.VC80.ATL'
An error occurred during the installation of assembly 'Microsoft.VC90.ATL or 'Microsoft.VC80.ATL' 下载 ...
- Mvc5 表单和HTML辅助方法
①表单的使用 在WebFrom里面你创建一个页面,页面上就会出<from></from>. 1,action和method属性 action表示目的,method表示表单传值方 ...