• Stars
    star
    138
  • Rank 264,508 (Top 6 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TFTP server and client implementation in C

TFTP的扩展和实现

这个项目是我在大学学习时开发的, 后来成为几乎所有人的课堂作业. http://www.ideawu.net/person/tftpx/

用C语言开发的在Linux平台上的TFTP(RFC1350)服务器端和客户端. 支持目录列表, 可变块大小(RFC2348). 传输模式只支持二进制模式.

停止等待(Stop and Wait)和自动重传(ARQ)机制作为数据传输的基本机制, 是网络编程必须要掌握的技能. TFTP 协议使用基于UDP的停止等待和超时重传机制来实现文件的可靠传输.

在查看 tftpx 的源码之前, 你最好先阅读 W.Richard.Stevens 的 TCP/IP Illustrated Volume 1: The Protocols(TCP/IP详解 卷1:协议).

tftpx 使用这样的代码来实现停止等待机制:

int send_packet(int sock, struct tftpx_packet *packet, int size){
	struct tftpx_packet rcv_packet;
	int time_wait_ack = 0;
	int rxmt = 0;
	int r_size = 0;

	for(rxmt = 0; rxmt < PKT_MAX_RXMT; rxmt ++){
		printf("Send block=%d\n", ntohs(packet->block));
		if(send(sock, packet, size, 0) != size){
			return -1;
		}
		for(time_wait_ack = 0; time_wait_ack < PKT_RCV_TIMEOUT; time_wait_ack += 20000){
			usleep(20000);
			// Try receive(Nonblock receive).
			r_size = recv(sock, &rcv_packet, sizeof(struct tftpx_packet), MSG_DONTWAIT);
			if(r_size >= 4 && rcv_packet.cmd == htons(CMD_ACK) && rcv_packet.block == packet->block){
				//printf("ACK: block=%d\n", ntohs(rcv_packet.block));
				// Valid ACK
				break;
			}
		}
		if(time_wait_ack < PKT_RCV_TIMEOUT){
			break;
		}else{
			// Retransmission.
			continue;
		}
	}
	if(rxmt == PKT_MAX_RXMT){
		// send timeout
		printf("Sent packet exceeded PKT_MAX_RXMT.\n");
		return -1;
	}

	return size;
}

More Repositories

1

ssdb

SSDB - A fast NoSQL database, an alternative to Redis
C++
8,173
star
2

icomet

A C1000K comet/push server built with C++, for web and mobile app
C++
1,522
star
3

Objective-C-RSA

Doing RSA encryption and decryption with Objective-C on iOS
Objective-C
1,151
star
4

c1000k

A tool to test if your OS supports 1 million connections(c1000k/c1m)
C
596
star
5

sim

Simple C++ network server framework
C++
351
star
6

cocoaui

Build adaptive UI for iOS Apps with flow-layout and CSS properties
Objective-C
325
star
7

ssdb-rocks

ssdb with rocksdb, rocksdb client-server support
C++
140
star
8

iphp

An everyone can understand PHP framework for web development
PHP
138
star
9

cocoaui-demos

Build Native iOS Apps with Simple HTML+CSS, Flow Layout
Objective-C
97
star
10

ssdb-docs

SSDB documentation source code
HTML
90
star
11

icomet-demos

Demos for icomet server
Java
85
star
12

ssdb-bin

SSDB pre-compiled binary
81
star
13

cpy

Cpy provides you a way to write Python codes in C syntax!
Python
62
star
14

webrtc-demo

WebRTC GIPS C/C++ API demos
C++
57
star
15

rtc

Real-Time Communication Infracture
C++
56
star
16

snappy-ios

The Snappy compression library for iOS
C++
37
star
17

CocoaUIDemo

moved to https://github.com/ideawu/cocoaui-demos
36
star
18

js-lottery

JS网页抽奖工具
HTML
14
star
19

libfast

Simple FIX and FAST protocol implementation
C++
13
star
20

tableview

JavaScript TableView, PagerView, SelectorView
HTML
12
star
21

phpvoip

SIP implement with PHP
PHP
10
star
22

ParallaxScroll

JavaScritp Parallax Scrolling, Swipe guesture
JavaScript
8
star
23

endlessssh

Tunneling SSH over HTTP
Python
8
star
24

pyhttp

Event driven HTTP library for Python
Python
6
star
25

ios_live_streaming

iOS/macOS 视频直播技术框架
Objective-C
6
star
26

manual

常用操作手册
6
star
27

iOSScrollPicker

iOS Scroll Picker
Objective-C
5
star
28

soc

Simpler Objective-C/Standard Objective-C Library
Objective-C
4
star
29

leetcode

C++
3
star
30

fifo_test

Shows how to properly read and write FIFO on Linux
C++
2
star
31

tovi-js

A JavaScript image gallery and HTML slider, with iPhone swipe effect.
CSS
1
star
32

libave

Audio Video Engine Library
C++
1
star