FormatException?那应该和send没什么关系,你的代码?

解决方案 »

  1.   

    参考:
    http://tech.ccidnet.com/pub/disp/Article?columnID=322&articleID=56279&pageNO=1
      

  2.   

    就是啊,应该没什么关系的。.NET我没用过sleep,用wait可能好点。
      

  3.   

    client:
    clientSocket.Connect(endPoint);
    byte []point1 = new byte [18];
    point1 = Encoding.ASCII.GetBytes(client_IP.ToString()+":"+txt_clientPort.Text.ToString()+":");
    clientSocket.Send(point1);
    Thread.Sleep(200);byte[] b_flength = Encoding.ASCII.GetBytes(file_length.ToString());clientSocket.Send(b_flength);
    Thread.Sleep(200);

    byte[] b_type = new byte[1];
    b_type = Encoding.ASCII.GetBytes("1");
    clientSocket.Send(b_type);
    Thread.Sleep(200);while(bytes_num < file_length)
    {
    bytes = one.Read(in_read,0,1024);
    clientSocket.Send(in_read,0,bytes,SocketFlags.None );

    bytes_num += bytes;
    }
    one.Close ();
    clientSocket.Shutdown(System.Net.Sockets.SocketShutdown.Send);
    clientSocket.Close();server:
    client = serverSocket.Accept();byte []endPoint = new byte[18];client.Receive(endPoint);
    string point2 = Encoding.ASCII.GetString (endPoint);byte []temp = new byte[50];client.Receive(temp);
    long file_length = Int64.Parse(Encoding.ASCII.GetString (temp));byte []type = new byte[1];
    client.Receive(type);if (file_length>0)
    {
    if (type[0] == 49)
    {
    string savePath = "";
    SaveFileDialog saveLog = new SaveFileDialog(); // Initialize the SaveFileDialog to specify the Log extension for the file.
    saveLog.DefaultExt = "*.bin";
    saveLog.Filter = "Files|*.*"; // Determine if the user selected a file name from the saveFileDialog.
    if(saveLog.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
    saveLog.FileName.Length > 0) 
    {
    savePath  = saveLog.FileName;
    }

    if (savePath.Equals(""))
    {
    client.Shutdown(System.Net.Sockets.SocketShutdown.Receive);
    client.Close();
    return;
    }
    FileStream two = File.Create (@savePath); byte[] to_write = new byte [1024];
    int bytes = 0;
    int bytes_num = 0; while(bytes_num < file_length)
    {
    bytes = client.Receive (to_write,1024,0);
    two.Write (to_write,0,bytes);
    bytes_num+=bytes;
    } two.Close ();
    }
    }这是大概的几行,应该可以看懂意思吧,有点乱。