iphone tcp connection

I want to establish tcp connection between iphone and PC. On PC QTspServer is running and working (was tested with other client application).

Here is the connection method i'm using on iphone:

- (IBAction)connectToServer:(id)sender { CFReadStreamRef read = NULL; CFWriteStreamRef write = NULL; NSString *host = @""; CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)host, 1000, &read, &write); CFWriteStreamOpen(write); int k = 0; }

The server on PC is not reacting. Any help is appropriate

By the way: Server is nothing more then a QTcpServer with replemented incomingConnection method. Here is the main function on server side:

int main(int argc, char **argv) { QApplication app(argc, argv); AbstractServer server; server.listen(QHostAddress::Any, 1000); QLabel label("Hello server"); label.setFixedSize(400, 400); label.show(); return app.exec(); }

-------------Problems Reply------------

The connection is established after something was sent to the server

Check that write isn't NULL after the call to CFStreamCreatePairWithSocketToHost. If it is, the socket connection is failing.

-(IBAction)connectToServer:(id)sender {
CFWriteStreamRef write = NULL;

NSString *host = @"";
int port = 1000;
CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)host, port, NULL, &write);
if (!write) {
// connection failed.
NSLog(@"Connection to %@:%d failed.",host,port);
} else {
// keep a reference to the output stream for later use.
self.output = (NSOutputStream*)write;
// the function that made the output stream has "Create" in its name, so
// this method owns the write stream & should release it.

Note that I store the output stream in a property of self. In your sample code, the stream isn't saved anywhere. You don't release it, so it still exists when the method exits, but there's no way of accessing it. If the sample -connectToServer: is representative, that error will prevent your object from sending anything to the server.

Category:iphone Views:0 Time:2011-01-30

Related post

  • Will the iPhone battery affected with an open TCP connection and not sending or receiving data? 2012-01-11

    Im currently developing a chat client for the iphone. Server-side there is a node.js with Socket.IO and on the iPhone an Socket.IO client ( https://github.com/DanLite/socket.IO-objc ) My Question is: Will the iPhone battery affected with an open TCP

  • Keep TCP connection persistent even after sub-routine calling connect() is end. How? 2010-09-20

    I have an application that calls connect() in a subroutine A. This sub-routine A is called when a button A is pressed. After connection has established, user can choose to click button B. This button B has to be programmed as a separate sub-routine.

  • How to establish Tcp connection between IOS and windows? 2011-01-22

    I'm trying to implement tcp connection between my Ipod as client and PC as server. I use QTcpServer to provide a server. What is the best way to realize the connection? --------------Solutions------------- Using CFSocket. An awesome cocoa class has b

  • How can an iOS app keep a TCP connection alive indefinitely while in the background? 2011-04-30

    An iPhone app, connecting to a remote server via TCP. The use scenarios are: app (user) sends data to server and server responds data back. server might send data to app while it does nothing. Assume that if app does not send data to server for 30 mi

  • Async Tcp Connection 2011-07-18

    I have a slight problem, I have a TCP class which connects to a server, transfers data then closes, this all works well except for if I connect, then stop it, it works, if I keep on doing this, it works, but on the fifth time the connection hangs wit

  • Receive an image on the iPhone (TCP Client) 2012-02-25

    I'm programming a client on the iPhone. I want to send some strings, and receive an image from the server. I found this tutorial (http://www.devx.com/wireless/Article/43551), it has been very useful. It works if I want to receive strings, but now I w

  • TCP connection quality in .NET 2008-10-15

    I have a mission-critical real-time data application that uses a TCP connection between the client and server. In some cases, the connection periodically dies (SocketException). No problem - just reconnect and move on. However, the customers aren't t

  • Concurrent open TCP connections in WCF service 2009-02-17

    We have a WCF service with multiple TCP endpoints. I am interested in monitoring the total number of concurrent open connections at any given time. Are there any perfmon counters that will allow us to do this out of the box? Note that number of insta

  • What is the preferred way to handle this TCP connection in C#? 2009-02-27

    I have a server application (singleton, simple .NET console application) that talks to a GlobalCache GC-100-12 for the purpose of routing IR commands. Various .NET WinForm clients on the local network connect to my server application and send ASCII c

  • Good TCP connection library for Java? 2009-03-17

    I am looking for a good TCP connection library from Java with the following facilities: 1. Retry on failed publishes 2. Multiple connections Which library have you sucessfully used. EDIT: Based on the comment changed the question to reflect which typ

  • Max TCP Connections to a machine 2009-03-18

    I am creating a Windows Service in .NET to which N number of client can connect. The service starts a TCP listener and accepts the client connections. The problem I am facing is that I can only open 10 connections to this service. The listener::Accep

  • In which cases should I close a TCP connection? 2009-03-22

    I'm currently writing a multi-process network game server (one gatekeeper process which tells players what games are currently running and allows them to create and join games, and a process per game instance). In which cases it would be useful for t

  • Risk of exploits "backwards" into outbound tcp connections 2009-03-26

    I am building a server application that will maintain connections to other applications by initiating TCP connections out through a firewall that is only open for outbound traffic to the relevant IP's ports that the application will connect to. What

  • Best way to check if a TCP connection is active 2009-03-31

    Given a list of IP addresses how do I programmatically check if the local machine still has active TCP connections to these IP Addresses? I am using C#. --------------Solutions------------- using System.Net.NetworkInformation IPGlobalProperties prope

  • sever/kill tcp connection in windows 2009-05-05

    I would like to see how a program responds when it's connection is severed. Aside from disabling the network card, is there a way to sever a tcp connection in Windows without killing the process, or the thread that owns the connections? -------------

  • Existing connection close when new TCP connections are made 2009-05-05

    I have a TCP listener service to which the clients connect. Lately I have started receiving this error related to disconnection. I connect around 20 clients to it and the connection works fine. But when I connect another 10 clients to the service, th

  • Do I need to heartbeat to keep a TCP connection open? 2009-05-14

    I have two components that that communicate via TCP/IP. Component A acts as a server/listener and Component B is the client. The two should communicate as quickly as possible. There can only ever be one connection at any time (though that is aside to

  • Submitting a link via iPhone -> Facebook Connect 2009-05-22

    I'm trying to post links through the iPhone facebook connect without using the feed control. I want to simulate how the publish a story works on facebooks website, where I pass a link, and it returns back an image, story title, and a link. Right now

  • Optimizing protocol opening operation over tcp connection opening 2009-05-25

    I'm designing a new protocol called DITP. It is a connection oriented protocol that would use TCP as transport layer. With common Internet protocols, when the TCP connection is established, the server starts by sending a greeting message to what the

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.238 (s). 11 q(s)