Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 73: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 74: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 75: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 76: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 77: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 78: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Net; using System.Net.Sockets; using System.Drawing; using System.Text; using System.Windows.Forms; namespace ex1g4 { public partial class Form1 : Form { private Socket temp; private EndPoint client_EndPoint; private Socket server_listenSocket; private Socket client_Socket; private bool isServer; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { isServer = false; try { char[] arr = { ':' }; String[] meu = textBoxIp.Text.Split(arr); int porto = int.Parse(meu[1]); client_EndPoint = new IPEndPoint(IPAddress.Parse(meu[0]), Convert.ToInt16(porto)); } catch (FormatException) { MessageBox.Show("Invalid IP address entered - needs n.n.n.n, for example 192.168.0.103"); return; } try { client_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); client_Socket.Connect(client_EndPoint); } catch (SocketException) { MessageBox.Show("Não é possível estabelecer a ligação"); return; } textBoxWriteMsg.Enabled = true; textBoxReadMsg.Enabled = true; buttonEnviar.Enabled = true; buttonDesligar.Enabled = true; buttonLigar.Enabled = false; buttonLancarServer.Enabled = false; textBoxIp.Enabled = false; System.Threading.ThreadStart ts = new System.Threading.ThreadStart(receiveLoop); System.Threading.Thread t1 = new System.Threading.Thread(ts); t1.Start(); } public void receiveLoop() { if (isServer) { while (true) { //textBoxIp.Text += "while "; try { temp = server_listenSocket.Accept(); textBoxWriteMsg.Enabled = true; textBoxReadMsg.Enabled = true; buttonEnviar.Enabled = true; } catch (ObjectDisposedException) { return; } try { Byte[] l_Buffer; string l_receivedString; while (temp.Connected) { l_Buffer = new Byte[100]; int received = temp.Receive(l_Buffer, l_Buffer.Length, SocketFlags.None); l_receivedString = System.Text.Encoding.UTF8.GetString(l_Buffer, 0, received); myDelegate updateDelegate = new myDelegate(updateMessageLog); // updateMessageLog é a funcao noutra thread que processa a string recebida updateDelegate(l_receivedString); // passagem da string para a funcao updateMessageLog atraves de um delegado } } catch (System.Exception) { if (temp != null) temp.Close(); // fecha os sockets do cliente e do servidor } textBoxWriteMsg.Enabled = false; textBoxReadMsg.Enabled = false; buttonEnviar.Enabled = false; } } else { temp = client_Socket; try { Byte[] l_Buffer; string l_receivedString; while (temp.Connected) { l_Buffer = new Byte[100]; int received = temp.Receive(l_Buffer, l_Buffer.Length, SocketFlags.None); l_receivedString = System.Text.Encoding.UTF8.GetString(l_Buffer, 0, received); myDelegate updateDelegate = new myDelegate(updateMessageLog); // updateMessageLog é a funcao noutra thread que processa a string recebida updateDelegate(l_receivedString); // passagem da string para a funcao updateMessageLog atraves de um delegado } } catch (System.Exception) { if (temp != null) temp.Close(); // fecha os sockets do cliente e do servidor } } } public delegate void myDelegate(String str); public void updateMessageLog(String str) { textBoxReadMsg.Text += "Remoto diz:\r\n" + str + "\r\n"; } private void button2_Click(object sender, EventArgs e) { buttonLancarServer.Enabled = false; textBoxIp.Enabled = false; buttonLigar.Enabled = false; isServer = true; server_listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { server_listenSocket.Bind(new IPEndPoint(IPAddress.Any, 4444)); } catch (SocketException) { MessageBox.Show("Já existe um servidor neste porto"); Application.Exit(); } server_listenSocket.Listen((int)SocketOptionName.MaxConnections); System.Threading.ThreadStart ts = new System.Threading.ThreadStart(receiveLoop); System.Threading.Thread t1 = new System.Threading.Thread(ts); t1.Start(); } private void buttonEnviar_Click(object sender, EventArgs e) { if (!isServer) { client_Socket.Send(Encoding.UTF8.GetBytes(textBoxWriteMsg.Text)); } else { temp.Send(Encoding.UTF8.GetBytes(textBoxWriteMsg.Text)); } textBoxReadMsg.Text += "Local diz: \r\n" + textBoxWriteMsg.Text + "\r\n"; textBoxWriteMsg.Text = ""; } private void buttonDesligar_Click(object sender, EventArgs e) { if (client_Socket != null) client_Socket.Close(); if (temp != null) temp.Close(); if (!isServer) { textBoxWriteMsg.Enabled = false; textBoxReadMsg.Enabled = false; buttonEnviar.Enabled = false; buttonLigar.Enabled = true; textBoxIp.Enabled = true; buttonDesligar.Enabled = false; buttonLancarServer.Enabled = true; } } private void Form1_Closing(object sender, CancelEventArgs e) { if (isServer) { try { if (server_listenSocket != null) { server_listenSocket.Close(); } } catch (Exception) { } } else { if (client_Socket != null) client_Socket.Close(); } } private void Form1_Load(object sender, EventArgs e) { buttonEnviar.Enabled = false; textBoxWriteMsg.Enabled = false; textBoxReadMsg.Enabled = false; buttonDesligar.Enabled = false; } } }