我为此尝试了 public partial class Form1 : Form
{
private TextBox newText;
private TextBox conStatus;
private ListBox results;
private Socket client;
private byte[] data = new byte[1024];
private int size = 1024;
public Form1()
{
InitializeComponent();
}
void ButtonConnectOnClick(object obj, EventArgs ea)
{
conStatus.Text = "Connecting...";
Socket newsock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("192.168.10.4"), 20916);
newsock.BeginConnect(iep, new AsyncCallback(Connected), newsock);
}
void ButtonSendOnClick(object obj, EventArgs ea)
{
if (newText.Text.Trim().ToString().Length == 0)
{
conStatuss("Write something to send!");
return;
}
byte[] message = Encoding.ASCII.GetBytes("Client:: " + newText.Text + "\"S(" + DateTime.Now.ToString("h:mm:ss tt") + ")\"");
addResult("Client:: " + newText.Text + "\"S(" + DateTime.Now.ToString("h:mm:ss tt") + ")\"");
//client.Send(message);
client.BeginSend(message, 0, message.Length, SocketFlags.None,
new AsyncCallback(SendData), client);
newText.Clear();
}
void ButtonDisconOnClick(object obj, EventArgs ea)
{
client.Close();
conStatus.Text = "Disconnected";
}
void Connected(IAsyncResult iar)
{
client = (Socket)iar.AsyncState;
try
{
client.EndConnect(iar);
conStatuss("Connected to: " + client.RemoteEndPoint.ToString());
client.BeginReceive(data, 0, size, SocketFlags.None,
new AsyncCallback(ReceiveData), client);
}
catch (SocketException)
{
conStatuss("Error connecting");
}
}
void ReceiveData(IAsyncResult iar)
{
try
{
Socket remote = (Socket)iar.AsyncState;
int recv = remote.EndReceive(iar);
string stringData = Encoding.ASCII.GetString(data, 0, recv);
addResult(stringData + "\"R(" + DateTime.Now.ToString("h:mm:ss tt") + ")\"");
/*
//to send back received text
byte[] message2 = Encoding.ASCII.GetBytes(stringData);
client.BeginSend(message2, 0, message2.Length, SocketFlags.None,
new AsyncCallback(SendData), client);
*/
}
catch (Exception eee)
{
conStatuss(eee.ToString());
}
}
void SendData(IAsyncResult iar)
{
Socket remote = (Socket)iar.AsyncState;
int sent = remote.EndSend(iar);
remote.BeginReceive(data, 0, size, SocketFlags.None,
new AsyncCallback(ReceiveData), remote);
}
delegate void SetTextCallback(string text);
private void conStatuss(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.conStatus.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(conStatuss);
this.Invoke(d, new object[] { text });
}
else
{
this.conStatus.Text = text;
}
}
public delegate void AddListBoxItem(string message);
public void addResult(string message)
{
//TODO: find out whats going on here
if (results.InvokeRequired)
{
//TODO: Which works better?
//AddListBoxItem albi = AddString;
//listBox.Invoke( albi, message );
results.Invoke(new AddListBoxItem(addResult), message);
}
else
this.results.Items.Add(message);
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
和JSPDF
。虽然HTML已成功呈现,但其CSS完全搞砸了。我还读过HTML2Canvas
不适合长页面的地方。
任何人都可以为我提供一个简单的Javascript代码,它可以获取DOM元素并生成PDF并维护其CSS吗?我真的很感激。感谢。