private void button5_Click(object sender, EventArgs e)
{
byte[] buffer=new byte[1016];
HostIP = IPAddress.Parse("127.0.0.1");
IPEndPoint point = new IPEndPoint(HostIP, Int32.Parse("11000"));
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(point);
//Thread thread = new Thread(new ThreadStart(Proccess));
// thread.Start();
int m_intSerial = 0;
int m_intBlocks = 0; //数据分割块数
int m_intLength = 0; //数据长度
int m_intMessageLength = 0;
int place = 0;
int m_intGetCount = 0;
string stringData ;
int recv = 0;
byte[] data1 = new byte[1016];
recv = socket.Receive(data1);
stringData = Encoding.ASCII.GetString(data1, 0, recv);
byte[] bytesF = Encoding.ASCII.GetBytes(stringData);
//byte[] data2 = new byte[m_intLength];
//byte[] bytesF = socket.Receive(data2);
// byte[] bytesF = socket.Receive(point); place = 0;
m_intSerial = BitConverter.ToInt32(bytesF, place);
place += 4;
m_intBlocks = BitConverter.ToInt32(bytesF, place);
place += 4;
m_intLength = BitConverter.ToInt32(bytesF, place);
place += 4;
m_intMessageLength = BitConverter.ToInt32(bytesF, place);
place += 4; byte[] data = new byte[m_intMessageLength]; //申明数据的总长
Array.Copy(bytesF, 16, data, m_intBlockLength * m_intSerial, m_intLength); //复制数据 m_intGetCount = m_intGetCount + 1;
Application.DoEvents(); while (m_intGetCount <=21)
{
byte[] bytes= new byte[1016];
// byte[] bytes = socket.Receive(data2);
place = 0;
m_intSerial = BitConverter.ToInt32(bytes, place);
place += 4;
m_intBlocks = BitConverter.ToInt32(bytes, place);
place += 4;
m_intLength = BitConverter.ToInt32(bytes, place);
place += 4;
m_intMessageLength = BitConverter.ToInt32(bytes, place);
place += 4; Array.Copy(bytes, 16, data, m_intBlockLength * m_intSerial, m_intLength); //复制数据 m_intGetCount = m_intGetCount + 1; // Application.DoEvents();
} MemoryStream ms = new MemoryStream(data);
Bitmap bm = (Bitmap)Image.FromStream(ms);
//Image image = Image.FromStream(ms);
bm.Save("f:\\dd4.jpg");
//image.Save("f:\\dd4.jpg");
socket.Close();
}
}
{
byte[] buffer=new byte[1016];
HostIP = IPAddress.Parse("127.0.0.1");
IPEndPoint point = new IPEndPoint(HostIP, Int32.Parse("11000"));
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(point);
//Thread thread = new Thread(new ThreadStart(Proccess));
// thread.Start();
int m_intSerial = 0;
int m_intBlocks = 0; //数据分割块数
int m_intLength = 0; //数据长度
int m_intMessageLength = 0;
int place = 0;
int m_intGetCount = 0;
string stringData ;
int recv = 0;
byte[] data1 = new byte[1016];
recv = socket.Receive(data1);
stringData = Encoding.ASCII.GetString(data1, 0, recv);
byte[] bytesF = Encoding.ASCII.GetBytes(stringData);
//byte[] data2 = new byte[m_intLength];
//byte[] bytesF = socket.Receive(data2);
// byte[] bytesF = socket.Receive(point); place = 0;
m_intSerial = BitConverter.ToInt32(bytesF, place);
place += 4;
m_intBlocks = BitConverter.ToInt32(bytesF, place);
place += 4;
m_intLength = BitConverter.ToInt32(bytesF, place);
place += 4;
m_intMessageLength = BitConverter.ToInt32(bytesF, place);
place += 4; byte[] data = new byte[m_intMessageLength]; //申明数据的总长
Array.Copy(bytesF, 16, data, m_intBlockLength * m_intSerial, m_intLength); //复制数据 m_intGetCount = m_intGetCount + 1;
Application.DoEvents(); while (m_intGetCount <=21)
{
byte[] bytes= new byte[1016];
// byte[] bytes = socket.Receive(data2);
place = 0;
m_intSerial = BitConverter.ToInt32(bytes, place);
place += 4;
m_intBlocks = BitConverter.ToInt32(bytes, place);
place += 4;
m_intLength = BitConverter.ToInt32(bytes, place);
place += 4;
m_intMessageLength = BitConverter.ToInt32(bytes, place);
place += 4; Array.Copy(bytes, 16, data, m_intBlockLength * m_intSerial, m_intLength); //复制数据 m_intGetCount = m_intGetCount + 1; // Application.DoEvents();
} MemoryStream ms = new MemoryStream(data);
Bitmap bm = (Bitmap)Image.FromStream(ms);
//Image image = Image.FromStream(ms);
bm.Save("f:\\dd4.jpg");
//image.Save("f:\\dd4.jpg");
socket.Close();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货