Last active
August 29, 2015 14:07
-
-
Save Seregamil/e16c2d87245d1a3b7400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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