P
pomparoee
Hi everyone.
I'm currently working on a project in c# where the client is a smart
device (wm5). The basic idea is remote access.
here's the code:
private void button1_Click(object sender, EventArgs e)
{
try
{
server = new TcpClient("192.168.1.7", 9050);
}
catch (SocketException se)
{
MessageBox.Show(se.Message+"Unable to connect to
server");
return;
}
//MessageBox.Show("Connection established! =)");
ns = server.GetStream();
while (true)
{
try
{
byte[] imgSize = new byte[4];
ns.Read(imgSize, 0, 4);
int len = BitConverter.ToInt32(imgSize, 0);
byte[] buffer = new byte[len];
ns.Read(buffer, 0, buffer.Length);
using (MemoryStream ms = new MemoryStream(buffer))
{
using (Bitmap res = new Bitmap(ms))
{
pictureBox1.Image = res;
pictureBox1.Invalidate();
}
}
buffer = null;
}
catch(Exception e1)
{
string s=e1.Message;
s=e1.StackTrace;
}
}
}
Anyway, the server sends images (in png format) at 1 fps (just for
testing, wanted to see if lower frequency will work) by first sending
the size and then the image itself. When i transfer a single image it
works fine. when the code specified runs i get an unknown exception
(when i tried using a try block i saw the exception was of the
exception class and had no message) when i construct the bitmap from
the stream.
here's the stacktrace:
StackTrace " at Microsoft.AGL.Common.MISC.HandleAr
(PAL_ERROR ar)\r\n at System.Drawing.Bitmap._InitFromMemoryStream
(MemoryStream mstream)\r\n at System.Drawing.Bitmap..ctor(Stream
stream)\r\n at SmartDeviceProject1.Form1.button1_Click(Object
sender, EventArgs e)\r\n at System.Windows.Forms.Control.OnClick
(EventArgs e)\r\n at System.Windows.Forms.Button.OnClick(EventArgs e)
\r\n at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam,
Int32 lParam)\r\n at System.Windows.Forms.Control._InternalWnProc(WM
wm, Int32 wParam, Int32 lParam)\r\n at
Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)\r\n at
System.Windows.Forms.Application.Run(Form fm)\r\n at
SmartDeviceProject1.Program.Main()\r\n" string
anyone have any idea how i may resolve this? Also, it would be nice to
see an open source bitmap streamer sample application, can anyone give
me a reference?
I'm currently working on a project in c# where the client is a smart
device (wm5). The basic idea is remote access.
here's the code:
private void button1_Click(object sender, EventArgs e)
{
try
{
server = new TcpClient("192.168.1.7", 9050);
}
catch (SocketException se)
{
MessageBox.Show(se.Message+"Unable to connect to
server");
return;
}
//MessageBox.Show("Connection established! =)");
ns = server.GetStream();
while (true)
{
try
{
byte[] imgSize = new byte[4];
ns.Read(imgSize, 0, 4);
int len = BitConverter.ToInt32(imgSize, 0);
byte[] buffer = new byte[len];
ns.Read(buffer, 0, buffer.Length);
using (MemoryStream ms = new MemoryStream(buffer))
{
using (Bitmap res = new Bitmap(ms))
{
pictureBox1.Image = res;
pictureBox1.Invalidate();
}
}
buffer = null;
}
catch(Exception e1)
{
string s=e1.Message;
s=e1.StackTrace;
}
}
}
Anyway, the server sends images (in png format) at 1 fps (just for
testing, wanted to see if lower frequency will work) by first sending
the size and then the image itself. When i transfer a single image it
works fine. when the code specified runs i get an unknown exception
(when i tried using a try block i saw the exception was of the
exception class and had no message) when i construct the bitmap from
the stream.
here's the stacktrace:
StackTrace " at Microsoft.AGL.Common.MISC.HandleAr
(PAL_ERROR ar)\r\n at System.Drawing.Bitmap._InitFromMemoryStream
(MemoryStream mstream)\r\n at System.Drawing.Bitmap..ctor(Stream
stream)\r\n at SmartDeviceProject1.Form1.button1_Click(Object
sender, EventArgs e)\r\n at System.Windows.Forms.Control.OnClick
(EventArgs e)\r\n at System.Windows.Forms.Button.OnClick(EventArgs e)
\r\n at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam,
Int32 lParam)\r\n at System.Windows.Forms.Control._InternalWnProc(WM
wm, Int32 wParam, Int32 lParam)\r\n at
Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)\r\n at
System.Windows.Forms.Application.Run(Form fm)\r\n at
SmartDeviceProject1.Program.Main()\r\n" string
anyone have any idea how i may resolve this? Also, it would be nice to
see an open source bitmap streamer sample application, can anyone give
me a reference?