The ONLY way you can send a message is if you receive one first. That's obviously a problem! I've tried to start multiple threads but I just don't know how. (I just got out of a threading lesson but 5 days ago) No matter how I do it, I can't figure out a way to be able to send messages over and over without having a block. Can anyone tell me how I'd be able to do this?
Here's the entire code:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.NativeInterop;
using System.Net.Sockets;
using System.Threading;
namespace MeteoraMSGClient
{
class Program
{
public static string MSG;
private static void MSGSendThread(WinsockClient Sender, object Arg)
{
MSG = Console.ReadLine();
Sender.Send(Encoding.ASCII.GetBytes(MSG));
}
static void Main(string[] args)
{
WinsockClient Client = new WinsockClient(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Client.OnConnect += new SocketEventCallback<WinsockClient, object>(Client_OnConnect);
Client.OnDisconnect += new SocketEventCallback<WinsockClient, object>(Client_OnDisconnect);
Client.OnReceive += new SocketEventCallback<WinsockClient, byte[]>(Client_OnReceive);
byte[] ClientRecvBuffer = new byte[255];
Client.Enable("**********", 9958, ClientRecvBuffer);
}
static void Client_OnReceive(WinsockClient Sender, byte[] Arg)
{
Console.WriteLine("New message!");
Console.WriteLine("\t >> " + Encoding.ASCII.GetString(Arg));
MSG = Console.ReadLine();
Sender.Send(Encoding.ASCII.GetBytes(MSG));
}
static void Client_OnDisconnect(WinsockClient Sender, object Arg)
{
Console.WriteLine("We have disconnected from the server");
}
static void Client_OnConnect(WinsockClient Sender, object Arg)
{
Console.WriteLine("We have connected to a server");
MSG = Console.ReadLine();
Sender.Send(Encoding.ASCII.GetBytes(MSG));
}
}
}






