rt
解决方案 »
- 求高手指点~关于C#打印 datagridview 大小问题
- c# webservice 调用dll
- VS 2005和VS.net 2005是一回事吗?
- 用C#创建资源文件遇到的问题
- 如何复制xml的节点=============================不同的上下文错误
- help!"并非所有的路径代码都有返回值"
- 音乐控制
- 怎么给socket服务端多添加一个线程啊???
- 如何让一个winform在三秒后自动关闭啊?
- C#如何根据域名获取IP!应该怎么写呢?
- 求救----急需----大家一起帮帮忙吧----高分求算法
- 定义了一个指定长度的数组(一维),但在程序运行时要改变数组的长度???该如何实现???
System.Threading.ThreadStart _delegate = null;
System.Threading.Thread _thread = null;
running = MakeSocket(); int loopTime = 0; while(running){
Console.WriteLine("*Start to listen a new connection. "+ (++loopTime).ToString()); try{
client = listener.AcceptSocket();
}catch(Exception e){
Console.WriteLine(e.Message);
break;
}
try{
WorkFlow workFlow = new WorkFlow(client); _delegate = new System.Threading.ThreadStart(workFlow.ThreadProc);
_thread= new System.Threading.Thread(_delegate);
_thread.Start();
}catch(System.Threading.ThreadAbortException e){
Console.WriteLine(e.Message);
listener.Stop();
return;
}catch(Exception e){
Console.WriteLine(e.Message);
break;
}
}
listener.Stop();
}
s1.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 30000); //30秒
s1.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 30000);
public WorkFlow(Socket socket){
_socket = socket;
dataMDL = new Datamdl();
} public void ThreadProc(){
int records, offset;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); Byte[] ReceiveBuffer = new Byte[256];
Byte[] SendBuffer = new Byte[1000]; DataTable dataTable; NetworkStream networkStream = new NetworkStream(_socket);
networkStream.Read(ReceiveBuffer, 0, 256); string receive = new string(encoding.GetChars(ReceiveBuffer));
Console.WriteLine("Received from client of inquire: [" + receive + "]"); string OperationType = receive.Substring(0, 3);
-----------------------------------
networkStream.Write(SendBuffer, 0, 1000);
//networkStream.Flush();
networkStream.Close();
_socket.Close();
//System.Threading.Thread.CurrentThread.Abort();
Console.WriteLine("Now End a conversation.****");
return;
}
private void String2ByteArray(ref Byte[] ArrayByte, int start, string convert, int length){
int len = ArrayByte.Length;
if(start+length>len) return;
if(convert.Length<length) length=convert.Length; Console.WriteLine("=Start to Convert=" + convert);
Byte[] tmpByteArray = System.Text.Encoding.Default.GetBytes(convert);
tmpByteArray.CopyTo(ArrayByte, start);
//Console.WriteLine("=End to Convert="+ System.Text.ASCIIEncoding.ASCII.GetChars(tmpByteArray));
} private Socket _socket;
private Datamdl dataMDL;
}
networkStream.Write(SendBuffer, 0, 1000);-_-!1000<1024,不会是这个问题吧。
现在把buffer加到8000。
但是和unix通讯的时候,unix只收到2048个字节。
unix上的程序没有问题。
我还试了一下。windows之间好象没有这个问题的。