Skip to content

Instantly share code, notes, and snippets.

@Seregamil
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seregamil/e16c2d87245d1a3b7400 to your computer and use it in GitHub Desktop.
Save Seregamil/e16c2d87245d1a3b7400 to your computer and use it in GitHub Desktop.
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace network
{
public class netWork
{
public netWork(){
}
public TcpClient startSession( string address, int port ){
return new TcpClient(address, port);
}
public void stopSession( TcpClient client ){
client.Close();
}
public string readText( TcpClient client ) {
if (client.Connected == false)
return string.Empty;
byte[] data = new byte[1024];
int recv = client.GetStream ().Read(data, 0, data.Length);
return Encoding.GetEncoding("windows-1251").GetString(data, 0, recv);
}
public void sendText( TcpClient client, string message ) {
if (client.Connected == false)
return;
client.GetStream().Write(Encoding.GetEncoding("windows-1251").GetBytes(message), 0, message.Length);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment