Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-31-2009, 04:25 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 1
NomenNescio is on a distinguished road
Default Network Problem - Help 4 Bachelor Thesis

Hello everybody!

I hope you can help me with my problem, I have to solve.
I need to set up a communication between a Java based server and an iPhone (via WiFi).
The server works perfectly and without errors, nevertheless, her is the code of it:

Code:
public static boolean initServer(int port) {
		System.out.println("Starting Server on: "+getIP()+":"+ port);
		boolean success = false;
		
		try {
			serverSocket = new ServerSocket(port);
			success = true;
	        try {
	            clientSocket = serverSocket.accept();
	            } catch (IOException e) {
	            	System.err.println("Accept failed.");
	        }
		} catch (IOException e) {
			System.err.println("Could not listen on port: " + port+ ".");
		}
		return success;
	}
	/**
	 * Generates a PrintWriter for Reading the clients data
	 * @return The PrintWriter
	 */
	public static PrintWriter getPrintWriter() {
		
        try {
            out = new PrintWriter(clientSocket.getOutputStream(), true);
        } catch (IOException e) {
            System.err.println("Could not generate PrintWriter.");
        }
        
        return out;
	}
	/**
	 * Generates a BufferedReader for sending data to the client
	 * @return The BufferedReader
	 */
	public static BufferedReader getBufferedReader() {
		 
		try {
			in = new BufferedReader(
						new InputStreamReader(
						clientSocket.getInputStream()));
		} catch (IOException e) {
            System.err.println("Could not generate BufferedReader.");
		}
		 return in;
	}
For the iPhoneApp i referred to this article by apple: Technical Q&A QA1652: Using NSStreams For A TCP Connection Without NSHost

My App connects to the server, but when I try to send to or receive from the server, the App and the iPhoneSimulator both crush.

Has anybody an idea, where I went wrong?
Is there a better way, to set up a communication?

Thank you for your help,

NomenNescio
NomenNescio is offline   Reply With Quote
Reply

Bookmarks

Tags
java, network connection, wifi

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 345
10 members and 335 guests
alexP, ClerurcifeDer, Duncan C, givensur, glenn_sayers, guusleijsten, JmayLive, Punkjumper, whitey99, yys
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:40 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0