Cannot send and read objects through sockets

I have these 4 classes to send objects through sockets. Message and Respond classes are just for
trials. I use their objects to send ıver the network. I do not get any compile time error or runtime error but
the code just does not send the objects. I used object input and output streams to send and read objects
in server (SOTServer) and in the client (SOTC) classes. When I execevute the server and client I can see
that the clients can connect to the server but they cannot send any objects allthough I wrote them inside the main method of client class. This code stops in the run() method but I could not find out why it
does do that. Run the program by creating 4 four classes.
Message.java
Respond.java
SOTC.java
SOTServer.java
Then execute server and then one or more clients to see what is going on.
Any ideas will be appreciated
thanks.
ASAP pls
//***********************************Message class**********************
import java.io.Serializable;
public class Message implements Serializable
private String chat;
private int client;
public Message(String s,int c)
client=c;
chat=s;
public Message()
client=0;
chat="aaaaa";
public int getClient()
return client;
public String getChat()
return chat;
//*******************************respond class*****************************
import java.io.Serializable;
public class Respond implements Serializable
private int toClient;
private String s;
public Respond()
public Respond(String s)
this.s=s;
public int gettoClient()
return toClient;
public String getMessage()
return s;
//***********************************SOTServer*********************
import java.io.*;
import java.net.*;
import java.util.Vector;
//private class
class ClientWorker extends Thread
private Socket client;
private ObjectInputStream objectinputstream;
private ObjectOutputStream objectoutputstream;
private SOTServer server;
ClientWorker(Socket socket, SOTServer ser)
client = socket;
server = ser;
System.out.println ("new client connected");
try
objectinputstream=new ObjectInputStream(client.getInputStream());
objectoutputstream=new ObjectOutputStream(client.getOutputStream());
catch(Exception e){}
public void sendToClient(Respond s)
try
objectoutputstream.writeObject(s);
objectoutputstream.flush();
catch(IOException e)
e.printStackTrace();
public void run()
do
Message fromClient;
try
fromClient =(Message) objectinputstream.readObject();
System.out.println (fromClient.getChat());
Respond r=new Respond();
server.sendMessageToAllClients(r);
System.out.println ("send all completed");
catch(ClassNotFoundException e){e.printStackTrace();}
catch(IOException ioexception1)
ioexception1.printStackTrace();
break;
Respond k=new Respond();
sendToClient(k);
}while(true);
public class SOTServer
ServerSocket server;
Vector clients;
public static void main(String args[]) throws IOException
SOTServer sotserver = new SOTServer();
sotserver.listenSocket();
SOTServer()
clients = new Vector();
System.out.println ("Server created");
public void sendMessageToAllClients(Respond str)
System.out.println ("sendToallclient");
ClientWorker client;
for (int i = 0; i < clients.size(); i++)
client = (ClientWorker) (clients.elementAt(i));
client.sendToClient(str);
public void listenSocket()
try
System.out.println ("listening socket");
server = new ServerSocket(4444, 6);
catch(IOException ioexception)
ioexception.printStackTrace();
do
try
ClientWorker clientworker=new ClientWorker(server.accept(), this);
clients.add(clientworker);
clientworker.start();
catch(IOException ioexception1)
ioexception1.printStackTrace();
while(true);
protected void finalize()
try
server.close();
catch(IOException ioexception)
ioexception.printStackTrace();
//*************************SOTC***(client class)*********************
import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;
class SOTC implements Runnable
private Socket socket;
private ObjectOutputStream output;
private ObjectInputStream input;
public void start()
try
socket= new Socket("127.0.0.1",4444);
input= new ObjectInputStream(socket.getInputStream());
output= new ObjectOutputStream(socket.getOutputStream());
catch(IOException e){e.printStackTrace();}
Thread outputThread= new Thread(this);
outputThread.start();
public void run()
try
do
Message m=new Message("sadfsa",0);
output.writeObject(m);
Respond fromServer=null;
fromServer=(Respond)input.readObject();
}while(true);
catch(NullPointerException e){run();}
catch(Exception e){e.printStackTrace();}
public SOTC()
start();
public void sendMessage(Message re)
try
Message k=new Message("sdasd",0);
output.writeObject(k);
output.flush();
catch(Exception ioexception)
ioexception.printStackTrace();
System.exit(-1);
public static void main(String args[])
SOTC sotclient = new SOTC();
try
System.out.println("client obje sonrasi main");
Message re=new Message("client &#305;m ben mesaj bu da iste",0);
sotclient.sendMessage(re);
System.out.println ("client gonderdi mesaji");
catch(Exception e) {e.printStackTrace();}

ObjectStreams send a few bytes at construct time. The OutputStream writes a header and the InputStram reads them. The InputStream constrcutor will not return until oit reads that header. Your code is probably hanging in the InputStream constrcutor. (try and verify that by getting a thread dump)
If that is your problem, tolution is easy, construct the OutputStreams first.

Similar Messages

  • HT201415 cannot send and receive imessages from phone number. Will not allow number to be ticked

    Cannot send and received imessages through phone numer.  Will not allow me to tick number

    Turn off iMessage and turn it back on.

  • I'm unable to send and receive email through Apple Mail 4.  I've checked my settings on Preferences, and my password to Gmail is up to date for syncing with IMAP, but it still won't connect.  Suggestions?

    I'm unable to send and receive email through Apple Mail 4.  I've checked my settings on Preferences, and my password to Gmail is up to date for syncing with IMAP, but it still won't connect.  Suggestions?

    I think it's trying to open it in a gMail eMail & is losing your gMail password that it needs log into gMail, but not 100% positive.
    Have you tried Right clicking or Control+click on the eMail link & choose Copy? Works on some, not others.

  • My iPhone5 cannot send and receive SMS using latest iOs. How can this problem be solved?

    my iPhone5 cannot send and receive SMS after I updated it to iOs 6.0.2. It used to be able to function normally when it was still using iOs 6.0.1.

    Since SMS/MMS is exchanged via your carrier's cellular network only, contact your carrier.

  • I cannot send and receive green sms on my mac yosimite

    I cannot send and receive green sms on my mac yosimite so fa every thing is well. Please help me to configure

    that depends on the hardware in your MacBook Pro.  Go to the Apple Menu in Yosemite, select "About This Mac".
    Once there, click the "System Report..." button.
    On the next window that opens, in the left sidebar under Hardware, select Bluetooth.
    On the right panel, near the top should be the following...
    Bluetooth Low Energy Supported: yes/no
    Handoff Supported: yes/no
    Instant Hotspot Supported: yes/no
    If any of those are no, they you will not have access to the majority of Handoff.
    NOTE: SMS functions (enabled after iOS 8.1 install), and iPhone to Mac calling features are WiFi only, and do not require the specific Bluetooth/Wifi hardware to function (I have a 2007 iMac and am able to send and receive calls from my iPhone on it, but I do not have, for example, Email/Keynote/Pages Handoff features between the two)

  • HT3042 I cannot send and ricive bluetooth via iphone 4s

    hi
    I cannot send and ricive bluetooth via iphone 4s
    How do I upload files to other phones?
    can you help me?
    have good time

    Correct. You cannot send and recieve files via Bluetooth to other phones with an iPhone.
    This is not, and never has been a feature of the iPhone.

  • Transport of PCD and Content objects through JDI.

    Hi all,
    Pls share the views about the trasport procedure for PCD and Content objects.
    Is it possible to transport PCD and Content objects through JDI?
    If it is possible, could you pls share how to configure the JDI setup?
    Thanks in advance,
    Kishore.

    Hi Kishroe,
    First, there is no supported, out of the box way to handle content objects in the JDI (now NWDI- NetWeaver Development Infrastructure) With that said, since it is a repository you could export your content package. Make it a zip file or something like that and add it to the repository.
    Again, I believe this is theoretically possible. I'm sure some of the other SDN members can provide an automated approach to do this.
    Good luck,
    John

  • Why I cannot send and receive emails when I am in other countries other my original

    Why I cannot send and receive emails when I am in other countries other my original country ?

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
    Try this: Delete the account in Mail and then set it up again.
     Cheers, Tom

  • How can i send and recieve mail through java

    HI All,
    plz let me know how can i send and receive mail through java.
    Regards:
    sachin kakkar
    http://www.datamansoftwares.com

    Using java mail API..
    try to search the forum for java mail... you find many question and answer.
    use the left search textfield

  • Cannot send email from Mail through .mac account

    I have recently opened a .mac account and started using the email service. It works fine online however I am having difficulty sending messages through the Mail application in Tiger.
    Whenever I attempt to send a message, a dialog box appears saying "Cannot send message using the server smtp.mac.com".
    I have tried looking at the setting in preferences. I have deleted and .mac a/c setting in Mail and re-set them up, all the problem persists.
    Please help!

    Hello David.
    Who is your ISP used for connecting to the internet and are you accessing an email account snd SMTP server in Mail provided by your ISP?
    If so, can you send messages with the email account and SMTP server provided by your ISP?
    Most, if not all ISPs now block the use of SMTP servers that are outside of their network (or not provided by the ISP used for connecting to the internet) on Port 25 which is the standard port used for SMTP servers. Some ISPs allow the use of an authenticated SMTP server only (such as the .Mac SMTP server) that is outside of their network on Port 25 but some block its use regardless.
    These restrictions are part of an overall effort to prevent spam emanating from the ISP's domain.
    Something to try.
    Go to Mail > Preferences > Accounts and under the Account Information tab for your .Mac account preferences at the SMTP server selection, select the Server Settings below for the .Mac SMTP server.
    Enter 587 in place of 25 in the Server Port field and when finished, select OK to save the changed setting.
    Test if this resolves the problem.
    If not and you are accessing an email account and SMTP server in Mail that is provided by your ISP used for connecting to the internet, select/use your ISP's SMTP server to send mail with your .Mac account which is invisible to all recipients.

  • Cannot send and recieve SMS

    I bought an iPhone 4s two days back! I just cannot send or receive SMS . The settings are all correct, can send and receive emails. Took out the sim from the new phone to the old one 3GS , no problems sending/ receiving SMS ! What do I do?

    If your 3GS works properly with the same SIM, then try going into Settings>General>Reset>Reset Network Settings. If it still does not work then you might have to restore it through iTunes. If it still continues to mal function I would call Apple customer support and try to get a replacement phone.

  • Cannot copy and paste objects in my project... Captivate 6

    Hello,
    I actually wrote about this yesterday, but I would like to mention it again because it's a big problem.  I have a Adobe Captivate 6 project, and I cannot copy and paste text captions, buttons, smart shapes, etc.  Do any of the experts out there have any advice?  I could probably send you a video of the problem if you'd like...
    Thank you in advance!
    Ryan

    Solution :  I created a new project and copied and pasted the slides from the old project to the new project.  Copy and paste works as it should in the new project.

  • Cannot send emails when outlook through another IS...

    When I am abroad I try to use Outlook to access my emails via whatever ISP is provided by my hotel. I can receive mails fine but I cannot send. I have tried changing default settings for outgoing mail with no success.

    You may have to use webmail instead, as the BT mail server will probably reject SMPT requests from outside of the BT network, to prevent spam.
    This may help
    http://bt.custhelp.com/app/answers/detail/a_id/10903/~/how-to-verify-email-addresses-%28to-avoid-get...
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • Cannot Send Y!Mail through Mail Please Help!

    Hi, I've tried everything on the Yahoo help page but I still can't send mail through my Mac mail client but I can receive mails. I tried to use these settings
    My Yahoo! Mail address (karty18 (at) yahoo (dot) com)
    Here are the basic server settings for Yahoo! Mail:
    Incoming Mail (POP3) Server: plus.pop.mail.yahoo.com (Use SSL, port: 995)
    Outgoing Mail (SMTP) Server: plus.smtp.mail.yahoo.com (Use SSL, default port: 25, 465, 587, use authentication)
    Account Name/Login Name: Your Yahoo! Mail ID (karty18)
    Password: My Yahoo! Mail password (yes, my password is correct)
    Still it doesn't work. I also tried the outgoing mail server: "Yahoo! SMTP Server" still no luck.
    And finally I tried to use custom port 587 just incase my IP is blocking port 465... no luck still. and for some reason when I select either outgoing server, it says offline in parenthesis but my mail accounts are all online (weird).
    I can receive mail alright but I cannot send. Please help me. I don't know what else to do from here. Thanks much.

    Some might find this useful.
    If you have a .co.uk address with Yahoo instead of .com, you can retrieve and send mail via the mail app using a free yahoo account.
    I have been doing this for years.
    Dave

  • Cannot send or receive emails through three networ...

    Hi, please help!  Running round in circles!
    Cannot send or recive emails on E71 all of a sudden has stopped working!
    Three network say its not them and Virgin media say its nhot them (email address is blueyonder one).
    Help please?
    How can I take all off phone and restart?

    You probably need to revalidate your hotmail account. I read of some issues a ouple days ago affecting hotmail users. Also many hotmail accounts have to be revalidated every 90 days. CLick on the email setup icon on your BlackBerry and log in to your BIS(BlackBerry Internet Srvice) account. Click on email accounts, see if you need to re-enter your password for your hotmail account.

Maybe you are looking for

  • Error message (?) in Chinese

    Anyone else order a book from Aperture and get messages in Chinese? I clicked order book, signed in, checked my order and selected the background viewer (vs continue) when it went to send the order to Apple. It showed the book order and the status wa

  • I can not contact itunes store to update alication

    hi, i can not contact itunes store with my iphone to update application

  • BLOB types

    Hi, Can someone explain me how to insert pictures in the following table? CREATE TABLE PICTURES ( ID NUMBER(12), PICNAME VARCHAR2(20), PICTURE BLOB); I have an oracle 11g Enterprise Edition Release 11.1.0.6.0. Thank you

  • Flash Accordion like features? Does Java support this?

    I come from a web media background. Mainly Coldfusion/SWL/Flash. I want to build a user interface similar to the Accordion piece that is provided by Flash. Can someone please point me in the right direction regarding what classes would be used to cre

  • What should i do about a black screen that won't shutoff?

    need som help with this my iphone 4 just went to a black screen?