硬件采集的数据怎样上传至服务器

硬件采集的数据怎样上传至服务器,第1张

首先你要写一个服务器程序,能接收来自外部的数据并做处理。

其次你要有通信硬件,硬件采集到的数据能传输到服务器。

(原理跟电脑需要插上网线,然后访问网页一样。)

我正在写一个相关的教程出来 ,全部公开,分享给你:网页链接

数据过大原因导致。
这种问题的可能原因大致可以分为三种:客户端应用程序的原因、网络的原因、服务器应用程序的原因。也就是说:可能是由于数据发送方过载,而没有向接收方发送数据、可能是为了通道很慢、或者是数据接收方的服务器太忙,从而无法从网络缓冲区读取数据。

不会,因为计算机网络通信是利用ip地址来寻找定位目标机器,用mac地址来转发到目标网关,而计算机名则是用来在局域网中为用户提供机器的识别和解析,简单点说,计算机名是给人看的,ip地址是收件人,mac是转发到每个区域的地址。
即便是IP和MAC同时重复了,但是 *** 作系统有6万多端口,两台机器同时上传用的端口不一样也不会造成影响。但是服务器不能重复。

前者是客户端,用来通过ftp或者sftp协议上传下载文件的 ------ 有它,你能连别人的服务器上传和下载
后者是服务端,用来搭建ftp或者sftp服务的(以便为别人通过ftp客户端访问自己的文件提供服务) ----有它,别人能连你的服务器上传下载。

控制台应用1(服务器):
using System;using SystemCollectionsGeneric;using SystemLinq;using SystemText;using SystemNet;using SystemNetSockets;using SystemThreading;
namespace ConsoleApplication1{ class Program { //服务器端

private static byte[] result = new byte[1024]; private static int myPort = 8081; static Socket serverSocket; static void Main(string[] args) { IPAddress ip = IPAddressParse("127001"); serverSocket = new Socket(AddressFamilyInterNetwork, SocketTypeStream, ProtocolTypeTcp); serverSocketBind(new IPEndPoint(ip, myPort)); serverSocketListen(10); ConsoleWriteLine("启动监听成功!终结点:"+serverSocketLocalEndPoint); Thread td1 = new Thread(ListenClient); td1Start(); ConsoleReadKey(); serverSocketClose(); } /// <summary> /// 监听客户端连接 /// </summary> static void ListenClient() { while (true) { Socket clientSocket = serverSocketAccept(); clientSocketSend(EncodingASCIIGetBytes("come on baby!")); Thread td2 = new Thread(ReceiveMessage); td2Start(clientSocket); } }
static void ReceiveMessage(object clientSocket) { Socket mySocket = (Socket)clientSocket; while (true) { try { int receiveNum = mySocketReceive(result); ConsoleWriteLine("接收到客户端({0})消息:{1}", mySocketRemoteEndPoint, EncodingASCIIGetString(result, 0, receiveNum));
} catch(Exception ex) { ConsoleWriteLine(exMessage); mySocketShutdown(SocketShutdownBoth); mySocketClose(); break; } } } }}
控制台应用2(客户端):
using System;using SystemCollectionsGeneric;using SystemLinq;using SystemText;using SystemThreading;using SystemNet;using SystemNetSockets;
namespace ConsoleApplication2{ class Program { //客户端 static byte[] result = new byte[1024]; static void Main(string[] args) { IPAddress ip = IPAddressParse("127001"); Socket clientSocket = new Socket(AddressFamilyInterNetwork, SocketTypeStream, ProtocolTypeTcp); try { clientSocketConnect(ip, 8081); ConsoleWriteLine("连接服务器成功!"); } catch { ConsoleWriteLine("连接服务器失败!任意键退出"); ConsoleReadKey(); return; } int receiveNum = clientSocketReceive(result); ConsoleWriteLine("接收到服务器消息:"+EncodingASCIIGetString(result,0,receiveNum));
while (true) { try { ConsoleWrite("你想对服务器说什么('0'键退出):"); string message = ConsoleReadLine(); if (!messageEquals("0")) { clientSocketSend(EncodingASCIIGetBytes(message)); ConsoleWriteLine("发送成功!"); } else { clientSocketShutdown(SocketShutdownBoth); clientSocketClose(); break; } } catch { clientSocketShutdown(SocketShutdownBoth); clientSocketClose(); break; } } ConsoleWriteLine("悄悄话已结束。任意键退出"); ConsoleReadKey(); } }}
写的一个小例子,用socket实现的,楼主参考下吧。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/13398474.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-28
下一篇 2023-07-28

发表评论

登录后才能评论

评论列表(0条)

保存