-
April 8th, 2010, 05:24 PM
#1
UDP Chat application
Hi, I am building small windows chat application. It consists of two part, UDP server and client and it works well while using my local IP (127.0.0.1) but nothing happens when i try to go over my router. I would appriciate any help, either to help with my code or give me some advice how to track what is going on when i start application. Now it seems like on login packets do not come to server but i am not sure. My source is big so i will place here what i think could be right, maybe it's not it .
This go on client load:
private void Form1_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
this.Text = "SGSclient: " + strIme;
//The user has logged into the system so we now request the server to send
//the names of all users who are in the chat room
Data msgZaSlanje = new Data ();
msgZaSlanje.cmdCommand = Command.Lista;
msgZaSlanje.strIme = strIme;
msgZaSlanje.strPoruka = null;
bytePodaci = msgZaSlanje.ToByte();
klijentSocket.BeginSendTo(bytePodaci, 0, bytePodaci.Length, SocketFlags.None, epServer,
new AsyncCallback(OnSlanje), null);
bytePodaci = new byte[1024];
//Start listening to the data asynchronously
klijentSocket.BeginReceiveFrom (bytePodaci,
0, bytePodaci.Length,
SocketFlags.None,
ref epServer,
new AsyncCallback(OnPrimanje),
null);
}
and then my UDP server should respond as it receives message but nothing happens.
This is my code for UDP server inicialization:
private void Form1_Load(object sender, EventArgs e)
{
try
{
CheckForIllegalCrossThreadCalls = false;
//---UDP socket---
serverSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
//---Uzima bilo koji IP i port broj 1000---
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse("78.0.69.84"), 1000);
//---Spajanje sa mrežnim sučeljem---
serverSocket.Bind(ipEndPoint);
IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
EndPoint epSender = (EndPoint) ipeSender;
//---Počinje primati podatke---
serverSocket.BeginReceiveFrom (bytePrimljeniPodaci, 0, bytePrimljeniPodaci.Length,
SocketFlags.None, ref epSender, new AsyncCallback(Primanje), epSender);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "UDP Server",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Thanks if you can help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|