Re: requesting some hints and libraries-Csharp
Hi there. I recoded the thing, it executes the functions just it seems it doesn't comunicate correctly. Here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
namespace Client_server
{
class Program
{
private static void server()
{
TcpListener serversocket = new TcpListener(11232);
TcpClient client = default(TcpClient);
serversocket.Start();
Console.WriteLine("server is up! ");
client = serversocket.AcceptTcpClient();
while(true)
{
NetworkStream net = client.GetStream();
byte[] bfrom = new byte[20000];
net.Read(bfrom, 0, bfrom.Length);
string event_message = Encoding.ASCII.GetString(bfrom);
if(event_message=="pat")
{
send(net, "asshole");
net.Flush();
}
}
void send(NetworkStream net, string data)
{
byte[] outst = Encoding.ASCII.GetBytes(data);
net.Write(outst, 0, outst.Length);
}
}
private static void client()
{
TcpClient client = new TcpClient();
client.Connect("127.0.0.1", 11232);
while(true)
{
NetworkStream net = client.GetStream();
byte[] bfrom = new byte[20000];
string event_message = Encoding.ASCII.GetString(bfrom);
bool b = false;
if (b == false)
{
string dat = "pat";
byte[] outst = Encoding.ASCII.GetBytes(dat);
net.Write(outst, 0, outst.Length);
net.Flush();
b = true;
}
if (event_message=="asshole")
{
Console.WriteLine("you are an asshole");
}
}
}
static void Main(string[] args)
{
Console.WriteLine("started the app");
var ser = new Thread(server);
ser.Start();
Thread.Sleep(250);
var cli = new Thread(client);
cli.Start();
Thread.Sleep(250);
ser.Join();
cli.Join();
}
}
}
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector