English 中文(简体)
(TCP)服务器/服务程序
原标题:(TCP) Server/Client program

I want to write (TCP) Server Client program. Client code should be in Objetive-C. Server side code should be in C#.

我已经写入了一些代码。 它正在起作用。 但问题是: 我将信息从客户端发送到服务器。 服务器正在接收信息。 但收到的信息看起来就像“ 加密” 的数据 。

code:

Objective-C
const uint8_t *rawdata = (const uint8_t*)[@"Welcome..." UTF8String];
[outputStream write:rawdata maxLength:strlen((const char *)rawdata)];

C#
char[] chara = new char[data.Length / sizeof(char)];
System.Buffer.BlockCopy(data, 0, chara, 0, chara.Length);
String content = new String(chara);
Console.WriteLine("Received data : " + content);

请帮我解决这个问题

最佳回答

我希望它能帮助你:

关于客户(目标C),我发送数据如下:

const uint8_t *str = (uint8_t *) [messageToSend cStringUsingEncoding:NSUTF8StringEncoding];

在 C# 服务器上,我不使用 < code> charles[] I 使用 < code> byte[] < >,我读了Socket的数据,然后我将其转换为 < code> string 如下(假设 < code> byte 数组的名称为 < code> data ):

string messageReceived = Encoding.UTF8.GetString(data, 0, bytesRead);

byteseRead 是一个整数,其大小与读取的字节大小相同(我从流中读到,因为我使用 TCP Sockets)。

我希望这能帮上忙

问题回答

看起来您正在以 UTF-8 发送数据, 但试图将它读成 UTF-16。 您需要使用 < a href=" http:// msdn. microsoft. com/ en- us/library/ system. text. encoding. utf8. aspx" rel = "nofollow" > Encoding. UTF8 转换 :

    var content = new UTF8Encoding(true,true).GetString(data)




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签