help me!!! socket problem..

G

Guest

Hi..
i having develop with vs.net2.0 and ce4.2.
but, occur critical problem..

debugging mode success, but deploy mode is fail..

have occur delay in socket communication?

help me... please!!!

<client..PDA>
public bool SendImage(Socket socket, byte[] imageContent)
{
try
{
int size = imageContent.Length;
int totalSent = 0, sent;
int leftData = size;

while (totalSent < size)
{
sent = socket.Send(imageContent, totalSent, leftData,
SocketFlags.None);
totalSent += sent;
leftData -= sent;
Thread.Sleep(700); <-- if no sleep in release mode,
fail server side, but debugging mode is success
}

return true;
}
catch (Exception)
{
return false;
}
}

<server-window app>
public Image ReceiveImage(Socket socket, long imageSize)
{
int recv;
int totaldata = 0;
int leftdata = (int)imageSize;
byte[] buffer = new byte[(int)imageSize];

while (totaldata < imageSize)
{
recv = socket.Receive(buffer, totaldata, leftdata,
SocketFlags.None);
if (recv == 0)
{
buffer = Encoding.ASCII.GetBytes("exit");
break;
}
totaldata += recv;
leftdata -= recv;
}
MemoryStream ms = new MemoryStream(buffer, true);
ms.Write(buffer, 0, buffer.Length);

Image image = Image.FromStream(ms);
ms.Flush();
ms.Close();

return image;
}
 
P

Paul G. Tobey [eMVP]

You'll have to be more-specific about what's going on. *What* error? You
say that you're running VS.NET2.0? What's that? .NET CF 2.0? 2.0SP1, I
hope! 2.0 itself is unsupported on CE.NET 4.2 devices, unless you mean
Pocket PC. If that *is* what you mean, say so!

Paul T.
 
G

Guest

thanks your reply..
i'm using netcf2.0 sp1 and ce4.2.
my problem is that received data received uncompletly.
send data and received data size are not same.

but, using Thread.sleep() method on send(), received data successfully.
why not?

sorry, i can't little english.

--
(e-mail address removed)


Paul G. Tobey said:
You'll have to be more-specific about what's going on. *What* error? You
say that you're running VS.NET2.0? What's that? .NET CF 2.0? 2.0SP1, I
hope! 2.0 itself is unsupported on CE.NET 4.2 devices, unless you mean
Pocket PC. If that *is* what you mean, say so!

Paul T.

pianism said:
Hi..
i having develop with vs.net2.0 and ce4.2.
but, occur critical problem..

debugging mode success, but deploy mode is fail..

have occur delay in socket communication?

help me... please!!!

<client..PDA>
public bool SendImage(Socket socket, byte[] imageContent)
{
try
{
int size = imageContent.Length;
int totalSent = 0, sent;
int leftData = size;

while (totalSent < size)
{
sent = socket.Send(imageContent, totalSent, leftData,
SocketFlags.None);
totalSent += sent;
leftData -= sent;
Thread.Sleep(700); <-- if no sleep in release mode,
fail server side, but debugging mode is success
}

return true;
}
catch (Exception)
{
return false;
}
}

<server-window app>
public Image ReceiveImage(Socket socket, long imageSize)
{
int recv;
int totaldata = 0;
int leftdata = (int)imageSize;
byte[] buffer = new byte[(int)imageSize];

while (totaldata < imageSize)
{
recv = socket.Receive(buffer, totaldata, leftdata,
SocketFlags.None);
if (recv == 0)
{
buffer = Encoding.ASCII.GetBytes("exit");
break;
}
totaldata += recv;
leftdata -= recv;
}
MemoryStream ms = new MemoryStream(buffer, true);
ms.Write(buffer, 0, buffer.Length);

Image image = Image.FromStream(ms);
ms.Flush();
ms.Close();

return image;
}
 
P

Paul G. Tobey [eMVP]

It's possible that you're closing the socket before transmit or receive is
complete. The other possibility is that you're using some class which does
character mapping from one thing to another (a class or method that expands
\n to \r\n, for example, or finds instances of \r\n and converts them to
single-character \n), or perhaps you're sending Unicode on one end and
assuming ASCII on the other end. The sleep hint seems to indicate the early
close of the socket, though, as the most-likely cause.

Paul T.

pianism said:
thanks your reply..
i'm using netcf2.0 sp1 and ce4.2.
my problem is that received data received uncompletly.
send data and received data size are not same.

but, using Thread.sleep() method on send(), received data successfully.
why not?

sorry, i can't little english.

--
(e-mail address removed)


Paul G. Tobey said:
You'll have to be more-specific about what's going on. *What* error?
You
say that you're running VS.NET2.0? What's that? .NET CF 2.0? 2.0SP1,
I
hope! 2.0 itself is unsupported on CE.NET 4.2 devices, unless you mean
Pocket PC. If that *is* what you mean, say so!

Paul T.

pianism said:
Hi..
i having develop with vs.net2.0 and ce4.2.
but, occur critical problem..

debugging mode success, but deploy mode is fail..

have occur delay in socket communication?

help me... please!!!

<client..PDA>
public bool SendImage(Socket socket, byte[] imageContent)
{
try
{
int size = imageContent.Length;
int totalSent = 0, sent;
int leftData = size;

while (totalSent < size)
{
sent = socket.Send(imageContent, totalSent,
leftData,
SocketFlags.None);
totalSent += sent;
leftData -= sent;
Thread.Sleep(700); <-- if no sleep in release mode,
fail server side, but debugging mode is success
}

return true;
}
catch (Exception)
{
return false;
}
}

<server-window app>
public Image ReceiveImage(Socket socket, long imageSize)
{
int recv;
int totaldata = 0;
int leftdata = (int)imageSize;
byte[] buffer = new byte[(int)imageSize];

while (totaldata < imageSize)
{
recv = socket.Receive(buffer, totaldata, leftdata,
SocketFlags.None);
if (recv == 0)
{
buffer = Encoding.ASCII.GetBytes("exit");
break;
}
totaldata += recv;
leftdata -= recv;
}
MemoryStream ms = new MemoryStream(buffer, true);
ms.Write(buffer, 0, buffer.Length);

Image image = Image.FromStream(ms);
ms.Flush();
ms.Close();

return image;
}
 
G

Guest

ok.. thanks..
always text data is receive successfuly.
only binary data is incorrect size received.

--
(e-mail address removed)


Paul G. Tobey said:
It's possible that you're closing the socket before transmit or receive is
complete. The other possibility is that you're using some class which does
character mapping from one thing to another (a class or method that expands
\n to \r\n, for example, or finds instances of \r\n and converts them to
single-character \n), or perhaps you're sending Unicode on one end and
assuming ASCII on the other end. The sleep hint seems to indicate the early
close of the socket, though, as the most-likely cause.

Paul T.

pianism said:
thanks your reply..
i'm using netcf2.0 sp1 and ce4.2.
my problem is that received data received uncompletly.
send data and received data size are not same.

but, using Thread.sleep() method on send(), received data successfully.
why not?

sorry, i can't little english.

--
(e-mail address removed)


Paul G. Tobey said:
You'll have to be more-specific about what's going on. *What* error?
You
say that you're running VS.NET2.0? What's that? .NET CF 2.0? 2.0SP1,
I
hope! 2.0 itself is unsupported on CE.NET 4.2 devices, unless you mean
Pocket PC. If that *is* what you mean, say so!

Paul T.

Hi..
i having develop with vs.net2.0 and ce4.2.
but, occur critical problem..

debugging mode success, but deploy mode is fail..

have occur delay in socket communication?

help me... please!!!

<client..PDA>
public bool SendImage(Socket socket, byte[] imageContent)
{
try
{
int size = imageContent.Length;
int totalSent = 0, sent;
int leftData = size;

while (totalSent < size)
{
sent = socket.Send(imageContent, totalSent,
leftData,
SocketFlags.None);
totalSent += sent;
leftData -= sent;
Thread.Sleep(700); <-- if no sleep in release mode,
fail server side, but debugging mode is success
}

return true;
}
catch (Exception)
{
return false;
}
}

<server-window app>
public Image ReceiveImage(Socket socket, long imageSize)
{
int recv;
int totaldata = 0;
int leftdata = (int)imageSize;
byte[] buffer = new byte[(int)imageSize];

while (totaldata < imageSize)
{
recv = socket.Receive(buffer, totaldata, leftdata,
SocketFlags.None);
if (recv == 0)
{
buffer = Encoding.ASCII.GetBytes("exit");
break;
}
totaldata += recv;
leftdata -= recv;
}
MemoryStream ms = new MemoryStream(buffer, true);
ms.Write(buffer, 0, buffer.Length);

Image image = Image.FromStream(ms);
ms.Flush();
ms.Close();

return image;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top