i'm trying write instant messenger
, has client application
, server application
should run separately on each client computer , server . of course clients communicating each other through socket
. , i'm saving each client's information on server . means client's application should send login information server , waite hear result . want know best way send information server ? should send through same socket
or ?
socket programming interesting topic in java. can use 2 main methodologies program instant messenger.
i assume know how programme sockets , working it's data streams. provide logic of instant messenger login.
1. server-client method
it requires 2 different progammes such client application , server application. server side user login can performed using method. it's possible transmit data encoded json or xml. received data decodes object. it's possible identify data message or login information server. consider following example.
- create data object transmit
class transmitdata {
private string username;//user name of sender private string password;//password of sender private string touser;//user name of receiver private string type;//message type message or login information //message types public static final string message = "message"; public static final string login_information = "login_information"; public transmitdata() { } //add getters , setters here }
then convert xml or json string
<transmit-data> <user-name></user-name> <password></password> <to-user></to-user> <message-type></message-type> </transmit-data>
after send xml data via socket connection
decode message @ server
identify message type , perform next actions
however server-client instant messengers not usable when server offline. not recommended when use in local area network.
2. peer-to-peer method
peer-to-peer instance messegers has 1 programme containing both server , client coding. it's hard develop , out of logic when using server-side user login. can add client side login messenger easily. it's possible add features search , add other users address book. become smarter when using. advantage not require server. think it's when use instant messenger in local area network.
Comments
Post a Comment