Created
December 30, 2015 07:57
-
-
Save AdamShehadeh/20a8ad866dae41c523db 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.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(); | |
} | |
} | |
} |
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.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