⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcptest.c

📁 很多仪器都输出同步时钟
💻 C
字号:
// file: tcptest -- see if we can talk tcp, or what

#include "excalibur.h"
#include "plugs.h"
#include "pio_lcd16207.h"


#define k_listen_port 80

typedef struct
	{
	int sniff_count;
	int sniff_pause;

	int inquiry_number;

	int tcp_plug;
	net_16 tcp_port_local;
	net_16 tcp_port_remote;
	net_32 tcp_ip_remote;
	host_32 tcp_sn_local; // our sequence number
	host_32 tcp_sn_remote; // their sequence number

	int tcp_sent_fin; // depending who closes first...

	} globals;

static globals g = {0};




// +---------------------------------
// | meat



int tcp_proc2(int plug_handle,
		void *context,
		ns_plugs_packet *p,
		void *payload,
		int payload_length)
	{
	char *w;
	int i;

	if(!payload)
		{
		printf("[tcp_proc2] connection closed, relistening\n\n");

		nr_plugs_listen
				(
				plug_handle,
				0,
				0
				);
		}

	printf("[tcp_proc2] data comes in, length %d\n");
	printf("[tcp_proc2] Data (mixed): ");

	w = payload;
	for(i = 0; i < payload_length; i++)
		{
		unsigned int c = *w++;
		if(c >= 0x20 && c <= 0x7f)
			printf("%c",c);
		else
			printf("(%02x)",c);
		}
	printf("\n");
	}

int main(void)
	{
	int result;
	int sniff_plug;

		{
		int tcp_plug;
		int tcp_plug_b;
		net_48 ea;



		result = nr_plugs_initialize(0,(void *)-2,0,0,0);
		printf("nr_plugs_initialize result = %d\n",result);


		nr_delay(1000);

		result = nr_plugs_ip_to_ethernet(0,nm_ip2n(192,168,10,25),
				&ea,0);

		result = nr_plugs_create
				(
				&tcp_plug,
				ne_plugs_tcp,
				k_listen_port,
				tcp_proc2,
				0,
				ne_plugs_flag_debug_rx | ne_plugs_flag_debug_tx
				);
		printf("nr_plugs_create result = %d\n",result);

		result = nr_plugs_listen
				(
				tcp_plug,
				0,
				0
				);
		printf("nr_plugs_listen result = %d\n",result);

		
		result = nr_plugs_create
				(
				&tcp_plug_b,
				ne_plugs_tcp,
				k_listen_port,
				tcp_proc2,
				0,
				ne_plugs_flag_debug_rx | ne_plugs_flag_debug_tx
				);
		printf("nr_plugs_create result = %d\n",result);

		result = nr_plugs_listen
				(
				tcp_plug_b,
				0,
				0
				);
		printf("nr_plugs_listen result = %d\n",result);

		while(1)
			{
			int c;
			char ch;

			if((c = nr_uart_rxchar(0)) > 0)
				{
				ch = c;
				nr_plugs_send(tcp_plug,&ch,1,0);
				}
			nr_plugs_idle();
			}

		}















	return 0;
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -