Подкорректировал класс, работоспособность ПОЛНАЯ.
Screen
Пример клиентской стороны с данным классом:
PHP код:
using System;
using network;
using System.Net;
using System.Net.Sockets;
using System.Threading ;
namespace client
{
class MainClass
{
public static void Main (string[] args)
{
string address = "127.0.0.1";
int port = 9595;
netWork net = new netWork ();
TcpClient client = null;
try{
client = net.startSession (address, port);
}
catch(Exception ex){
Console.WriteLine (ex.Message);
return;
}
Thread thread = new Thread (
delegate(){
timer( net, client ) ;
}
);
thread.Start ();
Console.WriteLine ("Connected!");
send: net.sendText (client, Console.ReadLine () );
goto send;
}
public static void timer(netWork net, TcpClient client){
Console.WriteLine ("Listening... {0}", client.ToString());
string text = string.Empty;
while ( true ) {
text = net.readText (client);
if (text == string.Empty)
break;
Console.WriteLine ("server sended -> " + text);
}
Console.WriteLine ("Stoped.");
}
}
}