Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8799045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:13:51+00:00 2026-06-14T00:13:51+00:00

i have found this amazing tutorial on raywenderlich.com: http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server it create a Twisted Python

  • 0

i have found this amazing tutorial on raywenderlich.com:

http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server

it create a Twisted Python server, and talk with app iphone chat, i would let the server talk also with a Java chat, and now i write some code, this is the python server:

from twisted.internet.protocol import Protocol, Factory
from twisted.internet import reactor


class IphoneChat(Protocol):
def connectionMade(self):
    #self.transport.write("""connected""")
    self.factory.clients.append(self)
    print "clients are ", self.factory.clients

def connectionLost(self, reason):
    self.factory.clients.remove(self)

def dataReceived(self, data):
    #print "data is ", data
    a = data.split(':')
    if len(a) > 1:
        command = a[0]
        content = a[1]

        msg = ""
        if command == "iam":
            self.name = content
            msg = self.name + " has joined"

        elif command == "msg":
            msg = self.name + ": " + content

        print msg

        for c in self.factory.clients:
            c.message(msg)

def message(self, message):
    self.transport.write(message + '\n')


factory = Factory()
factory.protocol = IphoneChat
factory.clients = []

reactor.listenTCP(1025, factory)
print "Chat server started"
reactor.run()

then i create a simple java example to connect to the server:

import java.net.*;
import java.io.*;
import java.util.*;

public class MyClassSocket  {

private ObjectInputStream sInput;       // to read from the socket
private ObjectOutputStream sOutput;     // to write on the socket
private Socket socket;

private String server, username;
private int port;

MyClassSocket(String server, int port, String username) {
    this.server = server;
    this.port = port;
    this.username = username;
}

private void display(String msg) {

    System.out.println(msg);      // println in console mode

}

public boolean start() {

    try {
        socket = new Socket(server, port);
    }
    // if it failed not much I can so
    catch(Exception ec) {
        display("Error connectiong to server:" + ec);
        return false;
    }

    String msg = "Connection accepted " + socket.getInetAddress() + ":" + socket.getPort();
    display(msg);

    try
    {

        sInput  = new ObjectInputStream(socket.getInputStream()); //<-------- block here
        sOutput = new ObjectOutputStream(socket.getOutputStream());
    }
    catch (IOException eIO) {
        display("Exception creating new Input/output Streams: " + eIO);
        return false;
    }

    return true;

}

public static void main(String[] args) {

    MyClassSocket client = new MyClassSocket("localhost",1025,"PieroJava");
    client.start();
}

}

The code freeze in the point i comment in the code above, and i can see in the server terminal that there is a new connection, and i can see in the client terminal that i connect but don’t go over here:

sInput  = new ObjectInputStream(socket.getInputStream());

how i can do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:13:52+00:00Added an answer on June 14, 2026 at 12:13 am

    I suggest not using ObjectInputStream and ObjectOutputStream. It will probably be challenging to get these to interact nicely with a Python server anyway, and they don’t implement a very good protocol anyway. I recommend a simpler protocol with better cross language support such as AMP.

    In any case, new ObjectInputStream seems to be expected to block until it can read bytes from the connection. If you want to make it succeed, your Twisted-based server will need to write the beginning of a Java object stream to the connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this analog clock tutorial here: http://www.codeproject.com/KB/selection/AnalogClockControl.aspx Now is it possible to
I have found this project on Codeplex. http://www.codeplex.com/ProjNET I need to integrate this code
I found an amazing typewriting effect at this website: http://www.9elements.com The header shows a
I have found this tutorial online http://net.tutsplus.com/tutorials/php/creating-a-php5-framework-part-1/ I have created myself a simple sort
I have found this link: http://www.jfree.org/forum/viewtopic.php?f=3&t=6314 Its back in 2007 where they agree that
I have found this piece of code in the Haskell sendfile package: http://patch-tag.com/r/mae/sendfile/snapshot/current/content/pretty/src/Network/Socket/SendFile/Linux.hsc --
I have found this great tutorial, about uploading files with a Flex app, using
When testing my iPhone app I have found it incredibly useful to log information
I have found this amazing control that does exactly what I need, only problem,
I have found this code http://djangosnippets.org/snippets/2283/ but I think it doesn't work with manytomanyfields

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.