Simplified version of the C# code with IP removed because I'm paranoid:
using System;
using System.Net;
using System.Net.Sockets;
.
.
.
static int linecount = 5;
static string[] lines = {"a", "b", "c", "defghijk", "this is a long string aaaaaaaa"};
.
.
.
static void blCommunicate() {
Console.Clear();
try {
Console.WriteLine("Creating the TCP server...");
IPAddress me = IPAddress.Parse("-IP-");
TcpListener serv = new TcpListener(me, -port-);
Console.WriteLine("Initializing server at " + me + ":-port-.");
serv.Start();
Console.WriteLine("Received endpoint " + serv.LocalEndpoint);
Socket s = null;
bool foundCli = false;
while (foundCli == false) {
Console.WriteLine("Awaiting connections.");
s = serv.AcceptSocket();
Console.WriteLine("Found connection: " + s.RemoteEndPoint);
Console.WriteLine("Begin transmit " + serv.LocalEndpoint + " -> " + s.RemoteEndPoint + "? Y/N");
if (Console.ReadKey().Key.ToString().ToUpper() == "Y") foundCli = true;
}
Console.WriteLine("Sending " + linecount + " strings...");
for (int x = 0; x < linecount; x ++) {
s.Send(new System.Text.ASCIIEncoding().GetBytes(lines[x]));
byte[] bread = new byte[1025];
int k = s.Receive(bread, 1024, SocketFlags.None);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(bread[i]));
}
Console.WriteLine("Ending server...");
s.Close();
serv.Stop();
} catch (Exception ex) {
Console.WriteLine("Exception encountered in net communication!");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
Console.Beep();
Console.WriteLine("Press ENTER to quit.");
Console.ReadLine();
}
I need to make a receiver for this in Blockland. The problem is I need the ASCII thing there to send anything, which needs a decoder Blockland-side. Also, the lines are going to be around 30 or 35 characters long - is this too much?