Untitled
unknown
csharp
3 years ago
1.4 kB
6
Indexable
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace testMail
{
class Program
{
static void Main(string[] args)
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ipAdd = System.Net.IPAddress.Parse("192.168.1.198");
IPEndPoint remoteEP = new IPEndPoint(ipAdd, 12345);
var c = new Credentials() { user = "mail@mail3.edu", pwd = "1234" };
var cmd = new Command() { serverCommand = 0, parameters = "my great parameters", credentials = c };
string jsonString = JsonConvert.SerializeObject(cmd);
socket.Connect(remoteEP);
byte[] byData = System.Text.Encoding.ASCII.GetBytes(jsonString);
socket.Send(byData);
socket.Disconnect(false);
socket.Close();
}
}
[Serializable]
public class Credentials
{
public string user { get; set; }
public string pwd { get; set; }
}
[Serializable]
public class Command
{
public int serverCommand { get; set; }
public string parameters { get; set; }
public Credentials credentials { get; set; }
}
}
Editor is loading...