Skip to content

Instantly share code, notes, and snippets.

@AdamShehadeh
Created December 30, 2015 07:57
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 AdamShehadeh/20a8ad866dae41c523db to your computer and use it in GitHub Desktop.
Save AdamShehadeh/20a8ad866dae41c523db to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net; //Unused in project
using System.Net.Sockets;
namespace SimpleClient
{
class Client
{
static void Main(string[] args)
{
TcpClient client = new TcpClient("127.0.0.1", 6969);
Console.WriteLine("[Trying to connect to server...]");
NetworkStream n = client.GetStream();
Console.WriteLine("[Connected]");
string ch = Console.ReadLine();
byte[] message = Encoding.Unicode.GetBytes(ch);
n.Write(message, 0, message.Length);
Console.WriteLine("--------------Sent--------------");
client.Close();
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net; //Unused in project
using System.Net.Sockets;
namespace SimpleServer
{
class Server
{
static void Main(string[] args)
{
TcpListener listen = new TcpListener(IPAddress.Any, 6969);
Console.WriteLine("[Listening...]");
listen.Start();
TcpClient client = listen.AcceptTcpClient();
Console.WriteLine("[Client connected]");
NetworkStream stream = client.GetStream();
byte[] buffer = new byte[client.ReceiveBufferSize];
int data = stream.Read(buffer, 0, client.ReceiveBufferSize);
string ch = Encoding.Unicode.GetString(buffer, 0, data);
Console.WriteLine("Message recieved: " + ch);
client.Close();
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment