向 IP 地址和端口发送消息

发布于 2024-10-21 23:18:37 字数 234 浏览 7 评论 0原文

过去几周我一直在努力解决这个问题。

我想要做的就是能够发送在 iphone/ipad 上创建的字符串并将其发送到特定的 IP 地址和端口号。然后该 IP 地址将返回“某些内容”,我想在 iphone/ipad 上显示一条消息。

我尝试过使用我遇到的示例项目,但永远无法让该死的东西发挥作用。我担心我会让这件事变得比实际需要的更加困难 - 但如果能提供一些帮助,我们将不胜感激。

谢谢萨姆

I have been trying get my head around this for last few weeks now.

All i want to do is be able to send a string created on the iphone/ipad and send that to a specific ip address and port number. That ip address will then return 'something' and i want to display a message back on the iphone/ipad.

I have tried using sample projects i came across , but can never get the damn thing to work. I fear i am making this alot harder than it needs to be - but some help would really be appreciated.

Thanks

Sam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

终遇你 2024-10-28 23:18:38

您想将其发送到同一网络中的设备吗?我已修改 GKRocket 以发送字符串,然后将其显示在第二个设备的 UIAlert 中: 这是我的修改:

-(void) sendPacket:(PacketType)packetType
{

    NSString * string = [[NSString alloc] initWithFormat:@"Message"];
    NSData *packet = [string dataUsingEncoding:NSUTF8StringEncoding];
    [manager sendPacket:packet ofType:packetType];
    [string release];
}

- (void) session:(SessionManager *)session didReceivePacket:(NSData*)data ofType:(PacketType)packetType
{
    UIAlertView * alert;
    NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    switch (packetType) {
        case PacketTypeString:
            alert = [[UIAlertView alloc] initWithTitle:@"Message" message:[NSString stringWithFormat:@"%@", str] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
            [alert show];
            [alert release];
            break;
        default:
            break;
    }
}

Do you want to send it to a device in the same network? I have modified GKRocket to send a string and then display it in a UIAlert in the second device: Here's my modification:

-(void) sendPacket:(PacketType)packetType
{

    NSString * string = [[NSString alloc] initWithFormat:@"Message"];
    NSData *packet = [string dataUsingEncoding:NSUTF8StringEncoding];
    [manager sendPacket:packet ofType:packetType];
    [string release];
}

- (void) session:(SessionManager *)session didReceivePacket:(NSData*)data ofType:(PacketType)packetType
{
    UIAlertView * alert;
    NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    switch (packetType) {
        case PacketTypeString:
            alert = [[UIAlertView alloc] initWithTitle:@"Message" message:[NSString stringWithFormat:@"%@", str] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
            [alert show];
            [alert release];
            break;
        default:
            break;
    }
}
如痴如狂 2024-10-28 23:18:37

用户 NSURLConnection 类,您可以在以下位置找到参考
http://开发人员。 apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html

NSURLConnection 对象提供执行 URL 请求加载的支持。 NSURLConnection 的接口很稀疏,仅提供启动和取消 URL 请求异步加载的控件。

NSURLConnection 的委托方法允许对象接收有关 URL 请求异步加载的信息回调。其他委托方法提供了允许委托自定义执行异步 URL 加载过程的工具。

user NSURLConnection class, you can find referenece at
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html

An NSURLConnection object provides support to perform the loading of a URL request. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request.

NSURLConnection’s delegate methods allow an object to receive informational callbacks about the asynchronous load of a URL request. Other delegate methods provide facilities that allow the delegate to customize the process of performing an asynchronous URL load.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文