Click here to Skip to main content
15,881,559 members
Home / Discussions / C#
   

C#

 
QuestionRe: Please help on this Pin
Perspx6-Sep-08 23:42
Perspx6-Sep-08 23:42 
AnswerRe: Please help on this Pin
DaveyM696-Sep-08 23:59
professionalDaveyM696-Sep-08 23:59 
AnswerRe: Please help on this Pin
Guffa7-Sep-08 0:35
Guffa7-Sep-08 0:35 
AnswerRe: Please help on this Pin
Kevin McFarlane7-Sep-08 6:53
Kevin McFarlane7-Sep-08 6:53 
AnswerFriggin homework... Pin
leckey7-Sep-08 6:59
leckey7-Sep-08 6:59 
AnswerRe: Please help on this Pin
nelsonpaixao7-Sep-08 13:02
nelsonpaixao7-Sep-08 13:02 
AnswerRe: Please help on this Pin
Christian Graus8-Sep-08 1:18
protectorChristian Graus8-Sep-08 1:18 
QuestionIOException 10054. Pin
leslie wu6-Sep-08 21:23
leslie wu6-Sep-08 21:23 
Hello all,

I am currently developing a application on windows mobile that can receive video image from webcam via a desktop. Here is my code:

namespace ABC
{
public partial class Form1 : Form
{

// private System.Net.IPHostEntry ips = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());

//---port nos and server IP address---
const Int32 PORTNO = 500;
string server_IP = "10.0.1.200";


//---size of the video image---
const int SIZEOFIMAGE = 341504;

//---use for connecting to the server---
TcpClient client;

//--used for sending and receiving data---
byte[] data;

//---used for receiving images from the server---
System.Threading.Thread t;

private void ReceiveImageLoop()
{


//---keep on receiving image until an error occurs---
while (ReceiveImage())
{

MessageBox.Show("in receive image");
}
//---display error message---
MessageBox.Show("Server has stopped responding. Please try restarting the video.");
}


//---Sends a message to the server---
private void SendMessage(string message)
{
//---adds a carriage return char---
message += "\n";
try
{
//---send the text
System.Net.Sockets.NetworkStream ns = null;
lock (client.GetStream())
{
ns = client.GetStream();
byte[] bytesToSend = System.Text.Encoding.ASCII.GetBytes(message);
//---sends the text---
ns.Write(bytesToSend, 0, bytesToSend.Length);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

//---receive video image from server---
public bool ReceiveImage()
{
MemoryStream s = new MemoryStream();
NetworkStream nws = client.GetStream();
int counter = 0;
int totalBytes = 0;

do
{

MessageBox.Show("trying to read data...");
//---read the incoming data---
int bytesRead = nws.Read(data, 0, client.ReceiveBufferSize); totalBytes += bytesRead;

//---write the byte() array into the memory stream---
s.Write(data, 0, bytesRead);
counter += 1;

//Loop Until totalBytes >= SIZEOFIMAGE
} while ( ! (totalBytes >= SIZEOFIMAGE));

//---display the image in the PictureBox control---
PictureBox1.Image = new Bitmap(s);


//---ask the server to send the next image---
SendMessage("Send");
return true;
}



public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (((Button)sender).Text == "Start")
{

//---connect to the server---
client = new TcpClient();
client.Connect(server_IP, PORTNO);

data = new byte [client.ReceiveBufferSize];
//---send message---
SendMessage("Send");

//---begin reading data asynchronously from the server---
t = new System.Threading.Thread(ReceiveImageLoop);
t.Start();


}
else
{
//---send message---
SendMessage("Stop");
t.Abort();


}
}

}
}


-------------

I keep on getting error message saying IOException for the code of lines highlighted in Bold. I have no idea why I am getting this as for my Windows version of the code, it is working smoothly.

Here are the details of the exception:

System.IO.IOException was unhandled
Message="An error message cannot be displayed because an optional resource assembly containing it cannot be found"
StackTrace:
at System.Net.Sockets.NetworkStream.Read()
at FYP.Form1.ReceiveImage()
at FYP.Form1.ReceiveImageLoop()
.
Help/suggetions from anyone will be highly apprecaited ! thanks !
AnswerRe: IOException 10054. Pin
Mbah Dhaim7-Sep-08 1:25
Mbah Dhaim7-Sep-08 1:25 
GeneralRe: IOException 10054. Pin
leslie wu7-Sep-08 4:56
leslie wu7-Sep-08 4:56 
GeneralRe: IOException 10054. Pin
Mbah Dhaim7-Sep-08 5:36
Mbah Dhaim7-Sep-08 5:36 
GeneralRe: IOException 10054. Pin
leslie wu8-Sep-08 3:02
leslie wu8-Sep-08 3:02 
QuestionSharing a lesson... Pin
MarkB7776-Sep-08 20:47
MarkB7776-Sep-08 20:47 
AnswerRe: Sharing a lesson... Pin
zafersavas6-Sep-08 21:51
zafersavas6-Sep-08 21:51 
AnswerRe: Sharing a lesson... Pin
Robert.C.Cartaino7-Sep-08 4:28
Robert.C.Cartaino7-Sep-08 4:28 
QuestionApplicationDeployment & HttpUtility Pin
AtulRane6-Sep-08 20:42
AtulRane6-Sep-08 20:42 
AnswerRe: ApplicationDeployment & HttpUtility Pin
Wendelius7-Sep-08 3:50
mentorWendelius7-Sep-08 3:50 
QuestionCreating custom controls Pin
Dewald6-Sep-08 20:24
Dewald6-Sep-08 20:24 
AnswerRe: Creating custom controls Pin
DaveyM696-Sep-08 23:46
professionalDaveyM696-Sep-08 23:46 
Questionerror: Exception has been thrown by the target of an invocation Pin
mehrnoosh6-Sep-08 19:15
mehrnoosh6-Sep-08 19:15 
AnswerRe: error: Exception has been thrown by the target of an invocation Pin
mehrnoosh8-Sep-08 20:22
mehrnoosh8-Sep-08 20:22 
QuestionHow can I get full path for a directory or file which I clicked on desktop or sth else in startup my application?? Pin
ersingenel6-Sep-08 14:56
ersingenel6-Sep-08 14:56 
AnswerRe: How can I get full path for a directory or file which I clicked on desktop or sth else in startup my application?? Pin
Ashfield7-Sep-08 8:46
Ashfield7-Sep-08 8:46 
Questiondynamic loaded ascx delegate event not firing in the parent form Pin
cmello6-Sep-08 14:11
cmello6-Sep-08 14:11 
QuestionRandom method Pin
MorganSim6-Sep-08 13:10
MorganSim6-Sep-08 13:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.