标题: 帮我看下为什么不能发送 [打印本页] 作者: 玫瑰花的葬礼 时间: 2013-4-9 12:35 标题: 帮我看下为什么不能发送 [code=csharp]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Data.SqlClient;
using System.Threading;
using System.Collections;
namespace Aserver
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
TextBox.CheckForIllegalCrossThreadCalls = false;
}
Thread threadWatch = null; //负责监听客户端的线程
Socket socketWatch = null; //负责监听客户端的套接字
Socket socConnection = null;
FileStream fs = new FileStream(path, FileMode.Open);
int PacketSize = 1024;
int PacketCount = (int)(fs.Length / ((long)PacketSize));
int LastDataPacket = (int)(fs.Length- ((long)(PacketSize * PacketCount)));
byte[] data = new byte[PacketSize];
for (int x = 0; x < PacketCount; x++)
{
fs.Read(data, 0, data.Length);
CommonModule.SendVarData(socConnection, data);
}
if (LastDataPacket != 0)
{
data = new byte[LastDataPacket];
fs.Read(data, 0, data.Length);
CommonModule.SendVarData(socConnection, data);
}
socConnection.Close();
fs.Close();
}
}
}
}
}[/code] 作者: 站长苏飞 时间: 2013-4-9 13:08
不使用线程看看能不能发送作者: 玫瑰花的葬礼 时间: 2013-4-9 14:02
[code=csharp]现在可以了 可是发一次就断开连接了
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Data.SqlClient;
using System.Threading;
using System.Collections;
namespace Aserver
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
TextBox.CheckForIllegalCrossThreadCalls = false;
}
Thread threadWatch = null; //负责监听客户端的线程
Socket socketWatch = null; //负责监听客户端的套接字
Socket socConnection = null;
FileStream fs = new FileStream(fileFullPath, FileMode.Open);
int PacketSize = 1024;
int PacketCount = (int)(fs.Length / ((long)PacketSize));
int LastDataPacket = (int)(fs.Length- ((long)(PacketSize * PacketCount)));
byte[] data = new byte[PacketSize];
for (int x = 0; x < PacketCount; x++)
{
fs.Read(data, 0, data.Length);
CommonModule.SendVarData(socConnection, data);
}
if (LastDataPacket != 0)
{
data = new byte[LastDataPacket];
fs.Read(data, 0, data.Length);
CommonModule.SendVarData(socConnection, data);
}
socConnection.Close();
fs.Close();
}