hi
i have developed a windows mobile based client app. i only want to send a simple string to the server running on pc via wifi connection.
i have already written the code and abt 2 months back it was working fine on emulator, but recently when i try to execute the code i didnt work on emulator nor on the device on which i deployed it.
when i press the login button the application does nothing and in the output screen i get
"The thread 0xb69a647e has exited with code 0 (0x0)."
It doesn't send any data to the server. but when i run the exe of the code in debug folder it works fine and sends data to the server
i am so confused that if exe is sending data why isnt the data sent through emulator or mobile device?
I am posting the code below...any help would be much appreciated.
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace DSDC
{
enum Command
{
Login,
Logout,
Message,
List,
Null
}
public partial class Form1 : Form
{
public Socket clientSocket;
public EndPoint epServer;
public string strName;
int portnum = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void LOGIN_Click(object sender, EventArgs e)
{
strName = textBox1.Text;
portnum =Convert.ToInt32(textBox3.Text);
try
{
clientSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
IPAddress ipAddress = IPAddress.Parse(textBox2.Text);
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, portnum);
epServer = (EndPoint)ipEndPoint;
Data msgToSend = new Data();
msgToSend.cmdCommand = Command.Login;
msgToSend.strMessage = null;
msgToSend.strName = strName;
byte[] byteData = msgToSend.ToByte();
clientSocket.BeginSendTo(byteData, 0, byteData.Length,
SocketFlags.None, epServer, new AsyncCallback(OnSend), null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "SGSclient");
}
}
private void OnSend(IAsyncResult ar)
{
try
{
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "SGSclient");
}
}
}
class Data
{
public Data()
{
this.cmdCommand = Command.Null;
this.strMessage = null;
this.strName = null;
}
public Data(byte[] data)
{
this.cmdCommand = (Command)BitConverter.ToInt32(data, 0);
int nameLen = BitConverter.ToInt32(data, 4);
int msgLen = BitConverter.ToInt32(data, 8);
if (nameLen > 0)
this.strName = Encoding.UTF8.GetString(data, 12, nameLen);
else
this.strName = null;
if (msgLen > 0)
this.strMessage = Encoding.UTF8.GetString(data, 12 + nameLen, msgLen);
else
this.strMessage = null;
}
public byte[] ToByte()
{
List<byte> result = new List<byte>();
result.AddRange(BitConverter.GetBytes((int)cmdCommand));
if (strName != null)
result.AddRange(BitConverter.GetBytes(strName.Length));
else
result.AddRange(BitConverter.GetBytes(0));
if (strMessage != null)
result.AddRange(BitConverter.GetBytes(strMessage.Length));
else
result.AddRange(BitConverter.GetBytes(0));
if (strName != null)
result.AddRange(Encoding.UTF8.GetBytes(strName));
if (strMessage != null)
result.AddRange(Encoding.UTF8.GetBytes(strMessage));
return result.ToArray();
}
public string strName;
public string strMessage;
public Command cmdCommand;
}
}