0% found this document useful (0 votes)
49 views4 pages

Tcplistener: Objhttp Setrequestheader

The document describes code for creating a TCP listener server in C# that accepts client connections on port 13000, receives data from connected clients, converts it to uppercase and sends it back. It also contains code for removing the close button from a Windows form and handling web socket requests.

Uploaded by

Maria LoOpez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views4 pages

Tcplistener: Objhttp Setrequestheader

The document describes code for creating a TCP listener server in C# that accepts client connections on port 13000, receives data from connected clients, converts it to uppercase and sends it back. It also contains code for removing the close button from a Windows form and handling web socket requests.

Uploaded by

Maria LoOpez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

[Link] "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.

0;
Windows NT 5.0)"

tcplistener

using System;
using [Link];
using [Link];
using [Link];
using [Link];

class MyTcpListener
{
public static void Main()
{
TcpListener server=null;
try
{
// Set the TcpListener on port 13000.
Int32 port = 13000;
IPAddress localAddr = [Link]("[Link]");

// TcpListener server = new TcpListener(port);


server = new TcpListener(localAddr, port);

// Start listening for client requests.


[Link]();

// Buffer for reading data


Byte[] bytes = new Byte[256];
String data = null;

// Enter the listening loop.


while(true)
{
[Link]("Waiting for a connection... ");

// Perform a blocking call to accept requests.


// You could also use [Link]() here.
TcpClient client = [Link]();
[Link]("Connected!");

data = null;

// Get a stream object for reading and writing


NetworkStream stream = [Link]();

int i;
// Loop to receive all the data sent by the client.
while((i = [Link](bytes, 0, [Link]))!=0)
{
// Translate data bytes to a ASCII string.
data = [Link](bytes, 0, i);
[Link]("Received: {0}", data);

// Process the data sent by the client.


data = [Link]();

byte[] msg = [Link](data);

// Send back a response.


[Link](msg, 0, [Link]);
[Link]("Sent: {0}", data);
}

// Shutdown and end connection


[Link]();
}
}
catch(SocketException e)
{
[Link]("SocketException: {0}", e);
}
finally
{
// Stop listening for new clients.
[Link]();
}

[Link]("\nHit enter to continue...");


[Link]();
}
}

if (new Regex("^GET").IsMatch(data)) {
Byte[] response = [Link]("HTTP/1.1 101
Switching Protocols" + [Link]
+ "Connection: Upgrade" + [Link]
+ "Upgrade: websocket" + [Link]
+ "Sec-WebSocket-Accept: " + Convert.ToBase64String (
[Link]().ComputeHash (
[Link] (
new Regex("Sec-WebSocket-Key:
(.*)").Match(data).Groups[1].[Link]() + "258EAFA5-E914-47DA-
95CA-C5AB0DC85B11"
)
)
) + [Link]
+ [Link]);

[Link](response, 0, [Link]);
}

[Link] = [Link];

then recreate the minimize and maximize buttons

private void button1_Click(object sender, EventArgs e)


{
[Link] = [Link];
}

private void button2_Click(object sender, EventArgs e)


{
[Link] = [Link];
}

Private Sub DisableCloseButton(ByVal hWnd As IntPtr)


Try 'captura de excepciones

Dim menuItemCount As IntPtr


Dim hMenu As IntPtr
'Obtener el manejador del menú de sistema del formulario
hMenu = GetSystemMenu(hWnd.ToInt32(), False)
'Obtener la cuenta de los ítems del menú de sistema.
'Es el menú que aparece al pulsar sobre el icono a la
izquierda
'de la Barra de título de la ventana, consta de los ítems:
Restaurar, Mover,
'Tamaño,Minimizar, Maximizar, Separador, Cerrar.
menuItemCount = GetMenuItemCount(hMenu.ToInt32())
'Quitar el ítem Close (Cerrar), que es el último de ese menú
RemoveMenu(hMenu.ToInt32(), menuItemCount.ToInt32() - 1,
MF_DISABLED Or MF_BYPOSITION)
'Quitar el ítem Separador, el penúltimo de ese menú, entre
Maximizar y Cerrar
RemoveMenu(hMenu.ToInt32(), menuItemCount.ToInt32() - 2,
MF_DISABLED Or MF_BYPOSITION)
'Redibujar la barra de menú
DrawMenuBar(hWnd.ToInt32())

'mostrar un mensaje con la excepción producida


Catch pollo As Exception
[Link]("Se ha producido la excepción: " + vbCrLf +
[Link], _
"Error del programa", [Link])
End Try
End Sub

ControlBox = False

You might also like