TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
herbert tamayo
NA
8
0
peer to peer chat error code
Jun 12 2007 12:50 AM
hi, well i have a serious problem with this code, it's a bout a peer to peer chat, basically my problem is that the port number of the socket is always 0, here is the code: basically yhe problem is in the process 2, event 2 PROCESS #1, TO LISTEN EVENT 1: private void cmdconectar_Click(object sender, EventArgs e) { //misock.recibirDatos(); threadchat = new Thread(new ThreadStart(quieroEscuchar)); threadchat.Start(); cmdconectar.Enabled = false; } EVENT 2 (CALLED FROM EVENT 1): public void quieroEscuchar() { int mioreja = Convert.ToInt32(txtmioreja.Text); IPEndPoint iplocalpunto; try { IPAddress myip = Dns.Resolve("localhost").AddressList[0]; iplocalpunto = new IPEndPoint(myip, mioreja); //ojo con lo que se digita } catch (SocketException socketerror) { marquesina.Text = socketerror.Message; return; } try { orejasocket = new windowSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); orejasocket.misockete.Bind(iplocalpunto); orejasocket.misockete.Listen(100); while (true) { finalizado.Reset(); orejasocket.misockete.BeginAccept(new AsyncCallback(acepComunic), orejasocket); finalizado.WaitOne(); } } catch (Exception error) { marquesina.Text = error.Message; } } EVENT 3 (CALLED FROM EVENT 2): public void acepComunic(IAsyncResult ar) { try { finalizado.Set(); windowSocket sintonizador = (windowSocket)ar.AsyncState; int nxsoc = validarSocket(); //ojo este se llama getavailblesocket sockcliente[nxsoc].misockete = (Socket)orejasocket.misockete.EndAccept(ar); //linea modificada sockcliente[nxsoc].socketRef = numsocket; //sockcliente[nxsoc].socketRef = Convert.ToInt32(txttuoreja.Text); sockcliente[nxsoc].usuRemoto = txttuip.Text; //ojo el compi me daba ref directa a form1_method, lo borre sockcliente[nxsoc].onConnected += new ConectarDelegado(onConnected); sockcliente[nxsoc].onDisconnected += new DesconectarDelegado(onDisconnected); sockcliente[nxsoc].onReadyReceive += new RecibirDelegado(onReceive); //en la linea anterior verificar si es asi o solo onReceive sockcliente[nxsoc].onReadySend += new EnviarDelegado(onReadySend); sockcliente[nxsoc].onConnectClose += new CerrarDelegado(onCloseRemote); //en la linea anterior verificar si es asi o solo onConnectClose sockcliente[nxsoc].onSocketMessage += new mensajeDelegado(onSockMessage); //verificar si es asi o onSockMessage sockcliente[nxsoc].onSendingFile += new enviandoDelegado(onEnvRec); //verificar si es asi o OnSending sockcliente[nxsoc].onReceiveFile += new recibirArchivoDelegado(onEnvRec); //verificar si es asi o OnSending sockcliente[nxsoc].recibirDatos(); ListViewItem lstusu = new ListViewItem(); lstusu.Text = nxsoc.ToString(); lstusu.SubItems.Add(sockcliente[nxsoc].misockete.RemoteEndPoint.ToString()); lstusu.SubItems.Add(txttuip.Text); lstpizarra.Items.Add(lstusu); } catch (Exception error) { marquesina.Text = "acepComunic : " + error.Message + error.Source.ToString(); } } ENVET 4 (CALLED FROM EVENT 3): private int validarSocket() { int x = -1; MessageBox.Show("Antes de entrar al lazo for: " + x.ToString()); for(x=0;x
-1) && (x < CONEXMAX)) MessageBox.Show("con este valor inicia el socket: "+x.ToString()); x = Convert.ToInt32(txttuoreja.Text); iniciarSocket(ref sockcliente[x], x); //prueba en vez de x de una vez el valor de lo digitado ancla marquesina2.Text= "socket seleccionado: "+x.ToString(); return x; } EVENT 5 (CALLED FROM EVENT 4): private void iniciarSocket(ref windowSocket misockete, int numsocket) { try { misockete = new windowSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); misockete.socketRef = numsocket; misockete.usuRemoto = txttuip.Text; //ojo los sigs el compi me daba ref directa a misockete, lo borre misockete.onConnected += new ConectarDelegado(onConnected); misockete.onDisconnected += new DesconectarDelegado(onDisconnected); misockete.onReadyReceive += new RecibirDelegado(onReceive); //en la linea anterior verificar si es asi o solo onReceive misockete.onReadySend += new EnviarDelegado(onReadySend); misockete.onConnectClose += new CerrarDelegado(onCloseRemote); //en la linea anterior verificar si es asi o solo onConnectClose misockete.onSocketError += new errorSocketDelegado(onSocketError); //el metodo anterior no fue incluido en acepComunic misockete.onSocketMessage += new mensajeDelegado(onSockMessage); //verificar si es asi o onSockMessage misockete.onSendingFile += new enviandoDelegado(onEnvRec); //verificar si es asi o OnSending misockete.onReceiveFile += new recibirArchivoDelegado(onEnvRec); //verificar si es asi o OnSending } catch (Exception error) { marquesina.Text = error.Message; } } EVENT 6 (CALLED FROM EVENT 3) //THIS EVENT IS OUTSIDE OF THE MAIN CLASS public void recibirDatos() { try { //esta linea no func estadoObjeto state = new estadoObjeto(); state.selectSocket = misockete; misockete.BeginReceive(state.buffer,0,estadoObjeto.bufferTam,SocketFlags.None, new AsyncCallback(recibirLlamada), state); } catch (Exception e) { RaiseSockErrEvent("Recibir : "+e.Message); CloseSocket(); } } PROCESS #2, TO CONNECT: EVENT 1: private void cmdplug_Click(object sender, EventArgs e) { int tuoreja = Convert.ToInt32(txttuoreja.Text); IPEndPoint iplocalpunto; try { IPAddress tuip = Dns.Resolve(txttuoreja.Text.ToString()).AddressList[0]; iplocalpunto = new IPEndPoint(tuip, tuoreja); } catch (SocketException error) { MessageBox.Show(error.Message); return; } int nxsoc = validarSocket(); try { sockcliente[nxsoc].socketRef = nxsoc; if (sockcliente[nxsoc] == null) iniciarSocket(ref sockcliente[nxsoc],nxsoc); if (!sockcliente[nxsoc].misockete.Connected) sockcliente[nxsoc].asincTCPIP(iplocalpunto); } catch (Exception error) { marquesina.Text="CMDPlug :"+error.Message; iniciarSocket(ref sockcliente[nxsoc],nxsoc); } } EVENT 2 (CALLED FROM EVENT 1): private int validarSocket() { int x = -1; MessageBox.Show("Antes de entrar al lazo for: " + x.ToString()); for(x=0;x
-1) && (x < CONEXMAX)) MessageBox.Show("con este valor inicia el socket: "+x.ToString()); x = Convert.ToInt32(txttuoreja.Text); iniciarSocket(ref sockcliente[x], x); //prueba en vez de x de una vez el valor de lo digitado ancla marquesina2.Text= "socket seleccionado: "+x.ToString(); return x; } EVENT 3 (CALLED FROM EVENT 2): private void iniciarSocket(ref windowSocket misockete, int numsocket) { try { misockete = new windowSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); misockete.socketRef = numsocket; misockete.usuRemoto = txttuip.Text; //ojo los sigs el compi me daba ref directa a misockete, lo borre misockete.onConnected += new ConectarDelegado(onConnected); misockete.onDisconnected += new DesconectarDelegado(onDisconnected); misockete.onReadyReceive += new RecibirDelegado(onReceive); //en la linea anterior verificar si es asi o solo onReceive misockete.onReadySend += new EnviarDelegado(onReadySend); misockete.onConnectClose += new CerrarDelegado(onCloseRemote); //en la linea anterior verificar si es asi o solo onConnectClose misockete.onSocketError += new errorSocketDelegado(onSocketError); //el metodo anterior no fue incluido en acepComunic misockete.onSocketMessage += new mensajeDelegado(onSockMessage); //verificar si es asi o onSockMessage misockete.onSendingFile += new enviandoDelegado(onEnvRec); //verificar si es asi o OnSending misockete.onReceiveFile += new recibirArchivoDelegado(onEnvRec); //verificar si es asi o OnSending } catch (Exception error) { marquesina.Text = error.Message; } }
Reply
Answers (
0
)
unions in c#
Formatting text that has been read from text file?