Código:
Application.Run(new Form1());
He probado a quitar las variables publicas y estaticas de arriba pero si las pongo en otros sitios ya no serian accesibles para los demas metodos que necesito hacer, que puedo hacer? que es lo que estoy haciendo mal??Código:
using System;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace ServerTest
{
public partial class Form1 : Form
{
public static IPAddress IP = IPAddress.Loopback;
public static TcpListener Listener = new TcpListener(IP, 22222);
public static Socket s = Listener.AcceptSocket();
public Form1()
{
InitializeComponent();
}
public void inicio()
{
try
{
//////sección ESCUCHA///////
Listener.Start();
//////CONEXION///////
MessageBox.Show("Conexion establecida con " + s.RemoteEndPoint);
/////RECEPCION/////////
byte[] buffer = new byte[100];
int bufferAux = s.Receive(buffer);
for (int i = 0; i < bufferAux; i++)
{
Convert.ToChar(buffer[i]);
}
/////ENVIO//////////
ASCIIEncoding codificacionEnvio = new ASCIIEncoding();
s.Send(codificacionEnvio.GetBytes(("test envio")));
}
catch
{
MessageBox.Show("Error de algun tipo ");
s.Close();
Listener.Stop();
inicio();
}
}
private void Form1_Load(object sender, EventArgs e)
{
inicio();
}
}
}
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace ServerTest
{
public partial class Form1 : Form
{
public static IPAddress IP = IPAddress.Loopback;
public static TcpListener Listener = new TcpListener(IP, 22222);
public static Socket s = Listener.AcceptSocket();
public Form1()
{
InitializeComponent();
}
public void inicio()
{
try
{
//////sección ESCUCHA///////
Listener.Start();
//////CONEXION///////
MessageBox.Show("Conexion establecida con " + s.RemoteEndPoint);
/////RECEPCION/////////
byte[] buffer = new byte[100];
int bufferAux = s.Receive(buffer);
for (int i = 0; i < bufferAux; i++)
{
Convert.ToChar(buffer[i]);
}
/////ENVIO//////////
ASCIIEncoding codificacionEnvio = new ASCIIEncoding();
s.Send(codificacionEnvio.GetBytes(("test envio")));
}
catch
{
MessageBox.Show("Error de algun tipo ");
s.Close();
Listener.Stop();
inicio();
}
}
private void Form1_Load(object sender, EventArgs e)
{
inicio();
}
}
}










Autor



En línea















