java - WriteInt not sending the integer -
i writing client server program. working except part. while looking @ code found out server not receiving user id sent client. problem either in outtoserver.writeint(uid); or in uid = din.readint();
.
thank much.
here code server part:
if("create event".equals(command)){ string eventnametxt = datain.readline(); system.out.println(eventnametxt); string location = datain.readline(); system.out.println(location); string description = datain.readline(); system.out.println(description); string startdate = datain.readline(); system.out.println(startdate); datainputstream din = new datainputstream(socket.getinputstream()); string enddate = datain.readline(); system.out.print(enddate); uid = din.readint(); system.out.print(uid); //get fullname of user creating event condition = "userid = "+uid; string creator = jdbc.selectlogin("fullname", "users", condition); //insert record in database string fields = "eventname,location,description,creator,userid,startdate,enddate"; string values = "'" + eventnametxt + "','" + location + "','" + description + "','" + creator + "'," + uid + ",'" + startdate + "','" + enddate + "'"; jdbc.insert("events", fields, values); dataout.writebytes("event created!!\n"); }
and code client side:
command = "create event"; try{ clientsocket = new socket("localhost", 6555); infromserver = new bufferedreader(new inputstreamreader(clientsocket.getinputstream())); dataoutputstream outtoserver = new dataoutputstream(clientsocket.getoutputstream()); //inform server user creating event outtoserver.writebytes(command + '\n'); //send information event outtoserver.writebytes(eventnametxt.gettext() + '\n'); outtoserver.writebytes(locationtxt.gettext() + '\n'); outtoserver.writebytes(eventdescription.gettext() + '\n'); outtoserver.writebytes(startdt.getdate().tostring() + '\n'); outtoserver.writebytes(enddt.getdate().tostring()+'\n'); // send userid corresponding person logged in , creating event outtoserver.writeint(uid); system.out.print(" "+uid+'\n'); response = infromserver.readline(); system.out.print("server response: "+response); if("event created!!".equals(response)){ joptionpane.showmessagedialog(null, response, "infobox: " + "response", joptionpane.information_message); outtoserver.writebytes("event added"+'\n'); this.dispose(); } }catch (ioexception ex){ logger.getlogger(eventsframe.class.getname()).log(level.severe, null, ex); }
according server code, you're reading lines 'datain' uid 'socket'.
Comments
Post a Comment