我有一個基於客戶端和服務器之間的TCP連接的應用程序,我可以發送/接收字符串,但我不知道如何發送字節數組:我用來從客戶端發送一個字符串到服務器是如下:從客戶端發送字節數組到服務器?
static void Send(string msg)
{
try
{
StreamWriter writer = new StreamWriter(client.GetStream());
writer.WriteLine(msg);
writer.Flush();
}
catch
{
}
}
對於爲例:
Send("CONNECTED| 84.56.32.14")
而在服務器側I使用以下代碼接收所發送的字符串:
void clientConnection_ReceivedEvent(Connection client, String Message)
{
string[] cut = Message.Split('|');
switch (cut[0])
{
case "CONNECTED":
Invoke(new _AddClient(AddClient), client, null);
break;
case "STATUS":
Invoke(new _Status(Status), client, cut[1]);
break;
}
}
任何人都可以幫助我修改上述功能,以發送/接收除字符串以外的字節數組。使用這樣的:
Send("CONNECTED | 15.21.21.32", myByteArray);
任何幫助將高度讚賞,三江源
一個空的catch塊ist總是一個相當糟糕的主意。 –