M
matrixed9
Hi Everyone
I need some urgent help in my school project. I have to implement
transfer of image from Pocket pc to desktop and vice versa over a
wireless network using tcp protocol.
I have managed to make the client ( PPC ) and Server (Desktop) to
connect and i can even send text data to each other without any
problem.
Now my problem is i want to send an image from PPC to Desktop and from
Desktop to PPC. Can anybody help me in this part of my code.
I am posting the data send and data received function on my client and
server app. Please help me how to modify it so that i can send and
receive images. PLease it'll be a gr8 favor.
Code for CLIENT (PPC App)
=======================================================================
public void WaitForData()
{
try
{
if ( pfnCallBack == null )
{
pfnCallBack = new AsyncCallback (OnDataReceived);
}
CSocketPacket theSocPkt = new CSocketPacket ();
theSocPkt.thisSocket = m_socClient;
// now start to listen for any data...
m_asynResult = m_socClient.BeginReceive (theSocPkt.dataBuffer
,0,theSocPkt.dataBuffer.Length
,SocketFlags.None,pfnCallBack,theSocPkt);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
private void cmdSend_Click(object sender, System.EventArgs e)
{
try
{
Object objData = txtDataTx.Text;
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString
());
m_socClient.Send (byData);
//txtDataTx.Clear();
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
public class CSocketPacket
{
public System.Net.Sockets.Socket thisSocket;
public byte[] dataBuffer = new byte[1];
}
public void OnDataReceived(IAsyncResult asyn)
{
try
{
CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState ;
//end receive...
int iRx = 0 ;
iRx = theSockId.thisSocket.EndReceive (asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
txtDataRx.Text = txtDataRx.Text + szData;
//y.WriteLine(szData);
WaitForData();
//MessageBox.Show("Done receiving ");
}
catch (ObjectDisposedException )
{
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
=====================================================================
For SERVER (DESKTOP App )
public class CSocketPacket
{
public System.Net.Sockets.Socket thisSocket;
public byte[] dataBuffer = new byte[1];
}
public void WaitForData(System.Net.Sockets.Socket soc)
{
try
{
if ( pfnWorkerCallBack == null )
{
pfnWorkerCallBack = new AsyncCallback (OnDataReceived);
}
CSocketPacket theSocPkt = new CSocketPacket ();
theSocPkt.thisSocket = soc;
// now start to listen for any data...
soc .BeginReceive (theSocPkt.dataBuffer
,0,theSocPkt.dataBuffer.Length
,SocketFlags.None,pfnWorkerCallBack,theSocPkt);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
public void OnDataReceived(IAsyncResult asyn)
{
try
{
CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState ;
//end receive...
int iRx = 0 ;
iRx = theSockId.thisSocket.EndReceive (asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
txtDataRx.Text = txtDataRx.Text + szData;
textBox1.Text = textBox1.Text + "\nMark:" + szData;
WaitForData(m_socWorker );
}
catch (ObjectDisposedException )
{
System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has
been closed\n");
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
====================================================================
The code above receives and sends only text , i want to modify it to
trasnfer image as byte array and receive on the other side and convert
back to image.
An immediate response wud be greatly appreciated
Thanks
I need some urgent help in my school project. I have to implement
transfer of image from Pocket pc to desktop and vice versa over a
wireless network using tcp protocol.
I have managed to make the client ( PPC ) and Server (Desktop) to
connect and i can even send text data to each other without any
problem.
Now my problem is i want to send an image from PPC to Desktop and from
Desktop to PPC. Can anybody help me in this part of my code.
I am posting the data send and data received function on my client and
server app. Please help me how to modify it so that i can send and
receive images. PLease it'll be a gr8 favor.
Code for CLIENT (PPC App)
=======================================================================
public void WaitForData()
{
try
{
if ( pfnCallBack == null )
{
pfnCallBack = new AsyncCallback (OnDataReceived);
}
CSocketPacket theSocPkt = new CSocketPacket ();
theSocPkt.thisSocket = m_socClient;
// now start to listen for any data...
m_asynResult = m_socClient.BeginReceive (theSocPkt.dataBuffer
,0,theSocPkt.dataBuffer.Length
,SocketFlags.None,pfnCallBack,theSocPkt);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
private void cmdSend_Click(object sender, System.EventArgs e)
{
try
{
Object objData = txtDataTx.Text;
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString
());
m_socClient.Send (byData);
//txtDataTx.Clear();
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
public class CSocketPacket
{
public System.Net.Sockets.Socket thisSocket;
public byte[] dataBuffer = new byte[1];
}
public void OnDataReceived(IAsyncResult asyn)
{
try
{
CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState ;
//end receive...
int iRx = 0 ;
iRx = theSockId.thisSocket.EndReceive (asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
txtDataRx.Text = txtDataRx.Text + szData;
//y.WriteLine(szData);
WaitForData();
//MessageBox.Show("Done receiving ");
}
catch (ObjectDisposedException )
{
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
=====================================================================
For SERVER (DESKTOP App )
public class CSocketPacket
{
public System.Net.Sockets.Socket thisSocket;
public byte[] dataBuffer = new byte[1];
}
public void WaitForData(System.Net.Sockets.Socket soc)
{
try
{
if ( pfnWorkerCallBack == null )
{
pfnWorkerCallBack = new AsyncCallback (OnDataReceived);
}
CSocketPacket theSocPkt = new CSocketPacket ();
theSocPkt.thisSocket = soc;
// now start to listen for any data...
soc .BeginReceive (theSocPkt.dataBuffer
,0,theSocPkt.dataBuffer.Length
,SocketFlags.None,pfnWorkerCallBack,theSocPkt);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
public void OnDataReceived(IAsyncResult asyn)
{
try
{
CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState ;
//end receive...
int iRx = 0 ;
iRx = theSockId.thisSocket.EndReceive (asyn);
char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
txtDataRx.Text = txtDataRx.Text + szData;
textBox1.Text = textBox1.Text + "\nMark:" + szData;
WaitForData(m_socWorker );
}
catch (ObjectDisposedException )
{
System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has
been closed\n");
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
====================================================================
The code above receives and sends only text , i want to modify it to
trasnfer image as byte array and receive on the other side and convert
back to image.
An immediate response wud be greatly appreciated
Thanks