rt

解决方案 »

  1.   

    public void Run(){
    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();
    }
      

  2.   

    网络问题吧。  把超时设定长一点试试.s1为Socket实例。
    s1.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 30000);  //30秒
    s1.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 30000);
      

  3.   

    public class WorkFlow{
    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;
    }
      

  4.   

    Byte[] SendBuffer = new Byte[1000];
    networkStream.Write(SendBuffer, 0, 1000);-_-!1000<1024,不会是这个问题吧。
      

  5.   

    xuxf的同事。
    现在把buffer加到8000。
    但是和unix通讯的时候,unix只收到2048个字节。
    unix上的程序没有问题。
      

  6.   

    networkStream.Write(SendBuffer, 0, 8000);
      

  7.   

    http://dev.csdn.net/develop/article/65/65798.shtm使用这个Socket写好的,不会出现这个问题。
      

  8.   

    自己提前一下。to  yangjundeng(天下无双) .一定要是同步做的呀。
      

  9.   

    unix上的程序接收到了数据。但是从2048个字节后面的内容都是0。
      

  10.   

    我试过一次一次传1024个字节的。但是还是失败。就是到了2048个字节的。
    我还试了一下。windows之间好象没有这个问题的。