Reputation: 2651
I would like to send motion JPEG from my computer to the Windows Phone telephone with global ip 89.232.123.122
. How to establish a connection with that mobile phone and push the mjpeg through the connection?
Upvotes: 1
Views: 1687
Reputation: 16
u must have web service and upload your picture to web service and save it in server or in database but i suggest save it in server ...
in Web Service :
[WebMethod]
public string UploadFile(byte[] f, string fileName)
{
try
{
MemoryStream ms = new MemoryStream(f);
FileStream fs = new FileStream
(System.Web.Hosting.HostingEnvironment.MapPath("~/ArchiveImages/") +
fileName, FileMode.Create);
ms.WriteTo(fs);
ms.Close();
fs.Close();
fs.Dispose();
return "ok";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
and in client app :
private void UploadFile(string filename)
{
try
{
ArchiveServiceObj.ArchiveServiceSoapClient srv = new ArchiveServiceObj.ArchiveServiceSoapClient();
MemoryStream stream = new MemoryStream();
picscannedimage.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic = stream.ToArray();
string sTmp = srv.UploadFile(pic, filename + ".jpg");
MessageBox.Show("File Upload Status: " + sTmp, "File Upload");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Upload Error");
}
}
Upvotes: 0
Reputation: 1410
for sending multimedia (like motion JPEG) use UDP instead of TCP.
in the sender side use this code :
UdpClient sendFrame = new UdpClient();
// your image is img:
Bitmap img = new Bitmap("pic.png");
// always send image
while (true)
{
MemoryStream memory_Stream = new MemoryStream();
// convert bitmap to jpg
SaveJPG100(img, memory_Stream);
byte[] byte_Of_Frame = memory_Stream.ToArray();
// send data on port 2000 on remote host
sendFrame.Send(byte_Of_Frame, byte_Of_Frame.Length,"89.232.123.122",2000);
}
// convert btm to jpg
public void SaveJPG100(Bitmap bmp, System.IO.Stream stream)
{
EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
bmp.Save(stream, GetEncoder(ImageFormat.Jpeg), encoderParameters);
}
// generate jpg description
public ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
on the receiver side use this code
UdpClient receiveFrame = new UdpClient(2000);
// recieve data from any ip address and any port
IPEndPoint remote = new IPEndPoint(IPAddress.ANY, 0);
while (true)
{
byte[] byte_Of_Frame = receiveFrame.Receive(ref remote);
MemoryStream ms = new MemoryStream(byte_Of_Frame);
pictureBox1.Image=(new Bitmap(ms));
}
Upvotes: 1