recv

Download HTTP thru sockets (C)

£可爱£侵袭症+ 提交于 2019-12-20 14:09:17
问题 Recently I started taking this guide to get myself started on downloading files from the internet. I read it and came up with the following code to download the HTTP body of a website. The only problem is, it's not working. The code stops when calling the recv() call. It does not crash, it just keeps on running. Is this my fault? Am I using the wrong approch? I intent to use the code to not just download the contents of .html-files, but also to download other files (zip, png, jpg, dmg ...). I

网络编程

只愿长相守 提交于 2019-12-20 04:01:12
网络编程 软件开发架构 c/s架构(client/server) ​ c:客户端 和 s:服务端 ​ 例如: QQ,微信,网盘,这一类都属于c/s架构,我们都需要下载一个客户端才能够运行 ​ ps:这里的客户端一般泛指客户端应用程序EXE,程序需要先安装后,才能运行在用户的电脑上,对用户的电脑操作系统环境依赖较大。 b/s架构(browser/server) ​ b:浏览器 和 s:服务器 ​ 例如:百度,淘宝网页,博客园这类都属于b/s架构,我们可以直接通过浏览器访问直接使用的应用 ​ ps:Browser浏览器,其实也是一种Client客户端,只是这个客户端不需要大家去安装什么应用程序,只需在浏览器上通过HTTP请求服务器端相关的资源(网页资源),客户端Browser浏览器就能进行增删改查。 用大白话来总结客户端和服务端的作用基本上可以理解为: 服务端:24小时不间断提供服务 客户端:什么时候想体验服务就去服务端寻求服务 b/s架构的本质其实也是c/s架构,两者都是用于两个程序之间通讯的开发 网络基础 网络编程技术起源 绝大部分先进技术的兴起基本都来自于军事,网络编程这项技术就是来源于美国军事,为了实现数据的远程传输 人类实现远程沟通交流的方式 - 插电话线的电话 - 插网线的大屁股电脑 - 插无线网卡的笔记本电脑 综上我们能够总结出第一个规律

基于TCP协议的网络摄像头的设计与实现

為{幸葍}努か 提交于 2019-12-20 03:19:37
一、摘要    总结一下基于C#的TCP传输协议的涉及到的常用方法及同步实现。 二、实验平台    Visual Studio 2010 三、socket编程的一些常用方法(同步实现) 3.1 命名空间    需要添加的命名空间 using System.Net; using System.Net.Socket; 3.2 构造新的socket对象 socket原型: public socket (AddressFamily addressFamily,SocketType sockettype,ProtocolType protocolType) (1) AddressFamily 用来指定socket解析地址的寻址方案,Inte.Network标示需要ip版本4的地址,Inte.NetworkV6需要ip版本6的地址; (2) SocketType 参数指定socket类型,Raw支持基础传输协议访问,Stream支持可靠,双向,基于连接的数据流; (3) ProtocolType 表示socket支持的网络协议,如常用的TCP和UDP协议。 3.3 定义主机对象 (1) IPEndPoint类 原型: a) public IPEndPoint(IPAddress address,int port) 参数address可以直接填写主机的IP,如"192.168.2.1"; b)

c++ posix sockets recv functionality

梦想与她 提交于 2019-12-20 02:15:40
问题 I have a perhaps noobish question to ask, I've looked around but haven't seen a direct answer addressing it and thought I might get a quick answer here. In a simple TCP/IP client-server select loop using bsd sockets, if a client sends two messages that arrive simultaneously at a server, would one call to recv at the server return both messages bundled together in the buffer, or does recv force each distinct arriving message to be read separately? I ask because I'm working in an environment

数字基带传输-搭建实用的 2PSK 通信系统

旧巷老猫 提交于 2019-12-19 10:57:07
通信原理实验五:数字基带系统 所花时间:3.5h 一、题目: 搭建一个实用的 2PSK 通信系统,要求其码元速率 1kHz,载波频率 5kHz,信 号带宽不超过 1.5kHz,并采用相干接收机对信号进行解调。 选择合适的传输波形,并确定收发滤波器的参数。 绘制发送信号波形及功率谱,以及无噪声条件下判决前的眼图。 在 AWGN 信道下对以上系统进行仿真,获得其误码率曲线(SNR=-3dB…8dB)。 二、题目解析 带通传输系统的系统模型: 可以看作基带传输系统+调制解调过程 因为之前的实验中已经完成了基带传输系统的仿真,2PSK的传输只需增加上调制解调过程即可,但有一些小细节需要注意。 三、需注意的细节 1、fs的选取 :此时的fs>fc+B/2,则即一个码元长度采样点数应当改变 2、抽样判决点 因为滤波器一定会有系统延时,带通传输系统的系统模型有三个滤波器,所以初始采样点必须加上三个系统延时 decision_idx = (1+(flt_delay+flt_delay+group_delay)):sa_per_sym:length(r_match_t); group_delay——解调时的系统延时 2个flt_delay——2个根升余弦滤波器的系统延时 四、完整的代码 clear all; close all; clc; %2PSK成型滤波器调制解调和误码率分析 %% RB =

Socket网络编程--FTP客户端(1)(Windows)

风流意气都作罢 提交于 2019-12-19 09:00:54
Socket网络编程--FTP客户端(1)(Windows)   已经好久没有写过博客进行分享了。具体原因,在以后说。   这几天在了解FTP协议,准备任务是写一个FTP客户端程序。直接上干货了。 0.了解FTP作用   就是一个提供一个文件的共享协议。 1.了解FTP协议   FTP有指令和响应码。FTP 控制帧即指 TELNET 交换信息,包含 TELNET 命令和选项。然而,大多数 FTP 控制帧是简单的 ASCII 文本,可以分为 FTP 命令或 FTP 消息。 FTP 消息是对 FTP 命令的响应,它由带有解释文本的应答代码构成。   像这种利用交换信息来进行简单的控制,这种协议,还真的很好玩的说。 命令与响应码部分信息如下       2. 安装一个FTP服务器   我们先安装一个FTP服务器,用于测试,这里是用FileZilla Server作为FTP服务器。   启动后,增加一个用户user/user 3.FTP客户端源代码讲解   下面这个是FTPAPI.h文件 1 #ifndef FTPAPI_H_INCLUDED 2 #define FTPAPI_H_INCLUDED 3 4 #include <stdio.h> 5 #include <winsock2.h> 6 7 SOCKET socket_connect(char *host, int port); 8

A more elegant way to use recv() and vector<unsigned char>

半城伤御伤魂 提交于 2019-12-18 13:09:19
问题 So far, I have this code sample: ... int nbytes =0; vector<unsigned char> buffer; buffer.resize(5000); nbytes = recv(socket, &buffer[0], buffer.size(),0); //since I want to use buffer.size() to know data length in buffer I do ... buffer.resize(nbytes); Is it some another way, to know data length in buffer without using resize() twice? Because it is not possible to receive data into vector that is not resized to proper size. I think reserve() method don't do allocation, according to the C++

Multiple calls to send() are merged into one call to recv()

让人想犯罪 __ 提交于 2019-12-17 19:21:57
问题 I have a client-server application. The client is sending a string followed by an integer using two distinct send() calls. These two data are supposed to be stored into two different variables on the server. The problem is that both variables sent are received on recv() call. Therefore, the two strings sent by the two distinct send() s are chained and stored in the buffer of the first recv() . server.c: printf("Incoming connection from client %s:%i accepted\n",inet_ntoa(clientSocketAddress

Determine if there is Data left on the socket and discard it

不羁的心 提交于 2019-12-17 14:56:55
问题 I'm writing an Interface under Linux which gets Data from a TCP socket. The user provides a Buffer in which the received Data is stored. If the provided Buffer is to small I just want to return an Error. First problem is to determine if the Buffer was to small. The recv() function just returns me the amount of bytes actually written into the Buffer. If I use the MSG_TRUNC flag stated on the recv() manpage it still returns me the same. Second problem is to discard the data still queued in the

What does Python's socket.recv() return for non-blocking sockets if no data is received until a timeout occurs?

五迷三道 提交于 2019-12-17 02:59:26
问题 Basically, I've read in several places that socket.recv() will return whatever it can read, or an empty string signalling that the other side has shut down (the official docs don't even mention what it returns when the connection is shut down... great!). This is all fine and dandy for blocking sockets, since we know that recv() only returns when there actually is something to receive, so when it returns an empty string, it MUST mean the other side has closed the connection, right? Okay, fine,