You are on page 1of 6

Materia: Programacin de Perifricos.

Maestro: Salvador Rentera Muoz.

Carrera: Ingeniera en Mecatrnica.

Reporte: Comunicacin entre 2 computadoras.

Integrantes: Mara Guadalupe Avelar Carrillo. Jos Carlos Jacobo Rodrguez.

Fecha de entrega: 13-Octubre-2011

Objetivo: El objetivo es lograr la comunicacin de 2 computadoras sin la necesitan de conectar algn cable para lograr la comunicacin o intercalar informacin. Planteamiento: Ya que tenemos el programa entramos le damos clic a inicio y buscamos smbolo del sistema y aparece el sig. cuadro:

Entonces ya que aparece este cuadro donde dice por ejemplo en mi lap aparece C:\Users\viclu_persa> le pones ipconfig y aparece la direccin de tu lap para que la pongas en el host para que puedas enviar informacin a las dems lap que se quieran conectar contigo.

Y el ip de mi computadora es el 192.168.3.53 entonces creas una red para que los dems usuarios te detecten le das clic derecho a la red inalmbrica y le das abrir el centro de redes y recursos compartidos, despus aparece un cuadro y seleccionas configurar una nueva conexin o red y despus aparece otro cuadro y seleccionas la ltima opcin configurar una red ad hoc inalmbrica (de equipo a equipo) y le da siguiente y aparece otro cuadro y le asignas un nombre y ya si tu deseas una contrasea y asi es como creas una red de equipo a equipo. Programa del Visual Basic: Host: NetComm.Host Server; private void MainDisplay_Load(object sender, EventArgs e)

{ Server = new NetComm.Host(2020); //Initialize the Server object, connection will use the 2020 port number Server.StartConnection(); //Starts listening for incoming clients //Adding event handling methods, to handle the server messages Server.onConnection += new NetComm.Host.onConnectionEventHandler(Server_onConnection); Server.lostConnection += new NetComm.Host.lostConnectionEventHandler(Server_lostConnection); Server.DataReceived += new NetComm.Host.DataReceivedEventHandler(Server_DataReceived); } private void MainDisplay_FormClosing(object sender, FormClosingEventArgs e) { Server.CloseConnection(); //Closes all of the opened connections and stops listening } void Server_DataReceived(string ID, byte[] Data) { Log.AppendText(ID + ": " + ConvertBytesToString(Data) + Environment.NewLine); //Updates the log when a new message arrived, converting the Data bytes to a string } void Server_lostConnection(string id) { if (Log.IsDisposed) return; //Fixes the invoke error Log.AppendText(id + " disconnected" + Environment.NewLine); //Updates the log textbox when user leaves the room } void Server_onConnection(string id) { Log.AppendText(id + " connected!" + Environment.NewLine); //Updates the log textbox when new user joined } string ConvertBytesToString(byte[] bytes) { return ASCIIEncoding.ASCII.GetString(bytes); } } } Client: NetComm.Client client; //The client object used for the communication private void MainDisplay_Load(object sender, EventArgs e) { client = new NetComm.Client(); //Initialize the client object //Adding event handling methods for the client client.Connected += new NetComm.Client.ConnectedEventHandler(client_Connected); client.Disconnected += new NetComm.Client.DisconnectedEventHandler(client_Disconnected);

client.DataReceived += new NetComm.Client.DataReceivedEventHandler(client_DataReceived); //Connecting to the host client.Connect("localhost", 2020, "renteria"); //Connecting to the host (on the same machine) with port 2020 and ID "Jack" } private void MainDisplay_FormClosing(object sender, FormClosingEventArgs e) { if (client.isConnected) client.Disconnect(); //Disconnects if the client is connected, closing the communication thread } void client_DataReceived(byte[] Data, string ID) { Log.AppendText(ID + ": " + ConvertBytesToString(Data) + Environment.NewLine); //Updates the log with the current connection state } void client_Disconnected() { Log.AppendText("Disconnected from host!" + Environment.NewLine); //Updates the log with the current connection state } void client_Connected() { Log.AppendText("Connected succesfully!" + Environment.NewLine); //Updates the log with the current connection state } private void SendButton_Click(object sender, EventArgs e) { client.SendData(ConvertStringToBytes(ChatMessage.Text),"chavita"); //Sends the message to the host ChatMessage.Clear(); //Clears the chatmessage textbox text } string ConvertBytesToString(byte[] bytes) { return ASCIIEncoding.ASCII.GetString(bytes); } byte[] ConvertStringToBytes(string str) { return ASCIIEncoding.ASCII.GetBytes(str); } } } Client 2: NetComm.Client client; //The client object used for the communication private void MainDisplay_Load(object sender, EventArgs e)

{ client = new NetComm.Client(); //Initialize the client object //Adding event handling methods for the client client.Connected += new NetComm.Client.ConnectedEventHandler(client_Connected); client.Disconnected += new NetComm.Client.DisconnectedEventHandler(client_Disconnected); client.DataReceived += new NetComm.Client.DataReceivedEventHandler(client_DataReceived); //Connecting to the host client.Connect("192.168.3.187", 2020, "chavita"); //Connecting to the host (on the same machine) with port 2020 and ID "Jack" } private void MainDisplay_FormClosing(object sender, FormClosingEventArgs e) { if (client.isConnected) client.Disconnect(); //Disconnects if the client is connected, closing the communication thread } void client_DataReceived(byte[] Data, string ID) { Log.AppendText(ID + ": " + ConvertBytesToString(Data) + Environment.NewLine); //Updates the log with the current connection state } void client_Disconnected() { Log.AppendText("Disconnected from host!" + Environment.NewLine); //Updates the log with the current connection state } void client_Connected() { Log.AppendText("Connected succesfully!" + Environment.NewLine); //Updates the log with the current connection state } private void SendButton_Click(object sender, EventArgs e) { client.SendData(ConvertStringToBytes(ChatMessage.Text),"renteria"); //Sends the message to the host ChatMessage.Clear(); //Clears the chatmessage textbox text } string ConvertBytesToString(byte[] bytes) { return ASCIIEncoding.ASCII.GetString(bytes); } byte[] ConvertStringToBytes(string str) { return ASCIIEncoding.ASCII.GetBytes(str);

} private void Log_TextChanged(object sender, EventArgs e) { } } } Material: Computadoras. Visual Basic (C##). Referencias: La red inalmbrica de la UPSZ.

You might also like