日期:2014-05-18  浏览次数:21086 次

winform 怎么发送文件给GPRS模块
winform 怎么发送文件给GPRS模块,求各位大侠帮帮忙,我刚接触GPRS通信,TCP协议一定要三次握手么?

------解决方案--------------------
你们有没有服务器?如果有那就好说一些了,pc和gprs模块都通过socket接入服务器,通过服务器中转传输。MC52iR3带有tcp/ip协议栈,可以直接使用模块的socket方面的AT指令。
如果没有服务器,那就要分析pc端的网络接入方式,如果是adsl那么可以实现pc端与gprs模块直接建立socket连接来传输,传输前需要通过短信把pc端的动态公网地址通知gprs模块。
如果是那种小区宽带,就有两个选择,前提条件是pc端也要连接一个gprs模块:
一是租一个网站空间,将文件上传到网站后短信通知gprs模块,gprs模块从网站下载;
二是利用gprs模块的数据数功能(类似传真那样的,可能需要移动网络运行商开通),这一块没做过不太了解。
------解决方案--------------------
这样的程序说大不大说小不小,socket服务器要做到性能与可靠性的完善不是一蹴而就的,我给你贴一个我这里的socket服务器类,仅供借鉴。你最好花更多的时间查阅msdn来完善这方面的知识。
第一部分:
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;
using System.Runtime.InteropServices;

namespace nsqserver
{
    [StructLayout(LayoutKind.Sequential)]
    public struct SendSegment
    {
        byte[] sendbuffer;
        SendPacketsElement[] sendelements;
        int offset;
        int count;
        public SendSegment(SendPacketsElement[] elements)
        {
            sendelements = elements;
            sendbuffer = null;
            offset = 0;
            count = 0;
        }
        public SendSegment(byte[] buffer, int ost, int cot)
        {
            sendbuffer = buffer;
            sendelements = null;
            offset = ost;
            count = cot;
        }
        public byte[] SendBuffer { get { return this.sendbuffer; } }
        public SendPacketsElement[] SendElments { get { return this.sendelements; } }
        public int Offset { get { return this.offset; } }
        public int Count { get { return this.count; } }
    }
    public enum RecvHasHeaders
    {
        On,
        Off
    }
    class SocketServer
    {
        byte[] buffers;
        byte[] sendbuffer;
        Socket[] sockets;
        SocketAsyncEventArgs[] sendargs;
        SocketAsyncEventArgs[] recvargs;
        SocketAsyncEventArgs[] acepargs;
        Queue<SendSegment>[] queues;
        Object[] objs;
        int recvbufferlen;
        int sockcount;
        int sendbufferlen;
        int sendindex;
        Object stackobj = new Object();
        RecvHasHeaders[] recvhasheader;
        Socket acceptsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        public event Func<int, byte[], int, int, int> RecvByteComplete;
        public event Func<int, byte[], int, int, int> RecvNoHeaderComplete;
        public event Action<int> SendPacketsComplete;
        public event Action<int> AcceptComplete;
        public event Action<int> SendComplete;
        public event Action<int> CloseComplete;
        byte[] inValue = new byte[] { 1, 0, 0, 0, 0x88, 0x13, 0, 0, 0x88, 0x13, 0, 0 };
        public SocketServer(int skcount, int rvbufferlen, int sdbufferlen, int queuecount, string ipadr, int port)
        {
            buffers = new byte[skcount * rvbufferlen];
            sendbufferlen = sdbufferlen;
            sendindex = 0;
            sendbuffer = new byte[sdbufferlen];
            sockets = new Socket[skcount];
            sendargs = new SocketAsyncEventArgs[skcount];
            recvargs = new SocketAsyncEventArgs[skcount];
            acepargs = new SocketAsyncEventArgs[skcount];
            queues = new Queue<SendSegment>[skcount];
            objs = new Object[skcount];
            recvhasheader = new RecvHasHeaders[skcount];
            recvbufferlen = rvbufferlen;
            sockcount = skcount;
            acceptsock.Bind(new IPEndPoint(IPAddress.Parse(ipadr), port));
            acceptsock.Listen(100);
            for (int i = 0; i < skcount; i++)
            {
                sockets[i] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                sendargs[i] = new SocketAsyncEventArgs();
                sendargs[i]