C代写 COMP9331 Computer Networks and Applications代写Java编程

Introduction已经完成所有要求的功能运行方式见题目具体函数大致功能见注释整体结构Server:主线程:用来监听socket链接,当客户端连接进来后创建单独的子线程为客户端服务子线程:用来处理各个客户端的消息Client:主线程:创建监听线程,然后获取用户输入命令,然后处理各项命令对服务器链接并创建对服务器返回消息的处理线程如果需要对其他客户端建立链接,则会对其他客户端创建返回消息处理线程 (主动链接其他客户端)监听线程:等待其他客户端的链接(用于private message),链接后创建返回消息的处 理线程(被其他客户端链接)返回消息处理线程:接受并处理服务器以及链接的其他客户端的消息消息的通信格式首先是4个字节的数据Len,表示后续数据具体的长度然后是Len字节的数据这样做是防止在tcp通信过程中相邻两个数据包粘包,导致消息不能区分重点数据结构解释struct socket_info{int fd; socket套接字struct sockaddr_in addr; 具体地址};struct user_data{char Name[30]; 用户名char Psd[30]; 密码struct socket_info Con; 建立链接的具体信息int State; -1表示从未登陆 0表示已经下线 1表示在线int Block; 0表示没有由于多次登录被惩罚 1与0相反struct timeval Time; 在block=1时有意义,表示惩罚开始的时间struct timeval LogOffTime; 在state不为-1时有意义,表示前一次下线时间int BlackList[100]; 第i个元素0表示把第i个用户没有拉黑 1表示拉黑int Msg_count; 待接收离线消息的总数char Msg[100][1000]; 离线消息char Privte_addr[40]; “ip 端口”用来让别的用户获取,并建立private链接};客户端代码部分:int state[100]; 第i个元素=0表示未占用 =1表示占用中struct socket_info P_List[100];char name_list[100][30];当state[i]=1时P_List[i]和name_list[i]有意义,分别表示建立了private链接的其他客户端的链接信息和用户名Client接受的消息格式分为三种:1、字符M后面接内容:这类消息直接屏幕输出M后的内容(因为服务器范围的大部分消息都不需要处理知识显示,所以服务器返回的大部分消息以及其他服务器发送对的私密消息都是这种格式)2、字符P后面接内容:这类消息表示的是这个socket链接的是其他客户端,内容为对方客户端的用户名3、IP 空格 端口号 空格 用户名:这类消息在客户端请求对别的客户端进行private链接时由服务器返回,表示的是目标客户端的ip,端口,以及用户名具体各功能的处理流程1)登陆:客户端在与服务器建立接连后,发送“名字 密码”格式的数据进行登陆验证服务器在判断后给出以下几种反馈:E1:名字不对E2:密码不对E3:名字不对,最后一次失败,开始惩罚时间E4:密码不对,最后一次失败,开始惩罚时间E5:惩罚时间中E6:该用户已登录OK:登陆成功在用户登陆成功后用户需要向服务器发送自己用于接受其他客户端接入的端口地址然后服务器对所有用户广播该用户登陆成功向该用户发送其离线时服务器缓存的消息2)message客户端发送命令格式M目标用户名 消息服务器在对目标进行判断后(是否存在以及是否把发送端拉黑)决定是否向目标用户发送消息(M消息),如果不发送则向发送端返回具体错误信息(M错误信息)如果可以发送但用户不在线,则服务器缓存下来,在目标用户上线后,发送给目标用户3)broadcast客户端发送命令格式B消息处理过程类似于message,不过是需要向所有在线用户发送,发送同样需要判断对方是否把发送端拉黑,如果有拉黑的用户,则需要向发送端反馈信息4)whoelse客户端发送命令格式W服务器查找当前所有在线的用户,将名字逐条发送给客户端5)whoelsesince客户端发送命令格式S秒数服务器查找当前所有在线的用户以及不在线并且前一次下线时间在S秒之类的用户,将名字逐条发送给客户端6)block客户端发送命令格式L用户名服务器需要判断该用户名是否存在,以及是否为发送方本人,以及是否已经拉黑,然后进行具体的拉黑处理再将结果发送给客户端7)unblock处理过程与上面类似8)startprivate客户端发送命令格式P用户名服务器判断用户名是否为发送方本人,如果不是且目标存在,则返回目标的ip,端口,名字,否则返回具体的错误消息客户端在收到具体的ip 端口 名字后,去向客户端B建立链接,同时向客户端B发送命令:P自己的名字这样客户端B就知道是谁与自己建立的链接9)private客户端判断是否与目标客户端已经有了链接,如果有,则向目标客户端发送M消息10)stopprivate客户端判断是否与目标客户端已经有了链接,如果有,则断开与目标客户端的链接Requirement1COMP3331/9331 Computer Networks and ApplicationsAssignment for Session 1, 2017Version 2.0Due: 11:59pm Friday, 28 April 2017 (Week 8)Mandatory Demo: Your regular lab slot (Week 9)1. Change LogVersion 1.0 released on 20 th March 2017.Version 2.0 released on 10 th April 2017.Added a command to close the p2p messaging session. This only applies for the extended version.2. Goal and learning objectivesInstant messaging applications such as WhatsApp, WeChat, Facebook Messenger, etc. are widelyused with millions of subscribers participating in them globally. In this assignment, you will havethe opportunity to implement your own version of an instant messaging application. In addition tobasic messaging functionality, you will also implement many additional services that are availablein many of the aforementioned applications. Your application is based on a client server modelconsisting of one server and multiple messaging clients. The clients communicate with the serverusing TPC. The server is mainly used to authenticate the clients and direct the messages (online oroffline) between clients. Besides, the server also has to support certain additional functions(presence notification, blacklisting, timeout, etc.). The extended version asks you to implementpeer-to-peer messaging that bypasses the server.2.1 Learning ObjectivesOn completing this assignment, you will gain sufficient expertise in the following skills:1. Detailed understanding of how instant messaging services work.2. Expertise in socket programming.3. Insights into designing an application layer protocol.3. Assignment SpecificationThere are two versions of this assignment, a standard version (with a total of 13 marks) and anextended version (with a total of 15 marks of which 2 marks are bonus marks). TheUpdates to the assignment, including any corrections and clarifications, will be posted on thesubject website. Please make sure that you check the subject website regularly for updates.2specifications for the extended version can be found in Section 5 of the specification. Note that thebonus marks may not be proportional to the amount of extra work that you will have to do. They arethere to encourage you to go beyond the standard assignment. The bonus marks can be used tomake up for lost marks in the lab exercises and the second programming assignment but NOT forany of the exams (mid-session and final).The assignment includes 2 major modules, the server program and the client program. The serverprogram will be run first followed by multiple instances of the client program (Each instancesupports one client). They will be run from the terminals on the same and/or different hosts.For the standard version, all messages between clients MUST be sent via the server. The extendedversion asks you implement additional functionality whereby two users can exchange messageswith each other directly (i.e. bypassing the server) in a peer-to-peer fashion.4.1. ServerThe server has the following responsibilities -User Authentication - When a new client requests for a connection, the server should prompt theuser to input the username and password and authenticate the user. The valid username andpassword combinations will be stored in a file called credentials.txt which will be in the samedirectory as the server program. An example credential.txt file is provided on the assignment page.Username and passwords are case-sensitive. We may use a different file for testing so DO NOThardcode this information in your program. You may assume that each user name and passwordwill be on a separate line and that there will be one white space between the two. If the credentialsare correct, the client is considered to be logged in (i.e. online) and a welcome message isdisplayed. When all messaging is done, a user should be able to logout from the server.On entering invalid credentials, the user is prompted to retry. After 3 consecutive failed attempts,the user is blocked for a duration of block_duration seconds (block_duration is a command lineargument supplied to the server), and cannot login during this duration (even from another IPaddress). While a user is online, if someone uses the same username/password to log in (even fromanother IP address), then this new login attempt is denied. If the username is invalid then blockaccess from that IP address for block_duration.Timeout - The server should keep track of all online users. If the server does not receive anycommands from a user for a period of timeout seconds (timeout is a command line argumentsupplied to the server), then the server should automatically log this user out. Note that, to beconsidered active, a user must actively issue a command. The receipt of a message does not count.Presence Broadcasts - The server should notify the presence/absence of other users logged into theserver, i.e. send a broadcast notification to all online users when a user logs in and logs out.List of online users - The server should provide a list of users that are currently online in responseto such a query from a user.Online history – The sever should provide a list of users that logged in for a user specified time inthe past (e.g. users who logged in within the past 15 minutes).Message Forwarding - The server should forward each instant message to the correct recipientassuming they are online.3Offline Messaging - When the recipient of a message is not logged in (i.e. is offline), the messagewill be saved by the server. When the recipient logs in next, the server will send all the unreadmessages stored for that user (timestamps are not required).Message Broadcast – The server should allow a user to broadcast a message to all online users.Offline messaging is not required for broadcast messages.Blacklisting - The server should allow a user to block / unblock any other user. For example, if userA has blocked user B, B can no longer send messages to A i.e. the server should intercept suchmessages and inform. B that the message cannot be forwarded. Blocked users also do not getpresence notifications i.e. B will not be informed each time A logs in or logs out.4.2. ClientThe client has the following responsibilities -Authentication - The client should provide a login prompt to enable the user to authenticate withthe server.Message - The client should allow the user to send a message to any other user and displaymessages sent by other users. The client should also allow the user to send a broadcast message toall online users.Notifications - The client should display presence notifications sent by the server about userslogging in and out from the server.Find users online - The client should provide a way for the user to obtain a list of all the userscurrently online from the server.Find online history – The client should provide a way for the user to obtain a list of all users whohad logged in within a user specified time period.Blacklist – The client should allow a user to block a user from sending any further messages. Theclient should also allow a user to unblock a user that was earlier blocked.4.3 Commands supported by the clientAfter a user is logged in, the client should support all the commands shown in the table below. Forthe following, assume that commands were run by user A.Command Descriptionmessage Send to through the server. If the user isonline then deliver the message immediately, else store themessage for offline delivery. If has blocked A, then amessage to that effect should be displayed for A. If the isnot present in the credentials file (i.e. invalid user) or is self (A)then an appropriate error message should be displayed. Theused in our tests will be a few words at most.broadcast Send to all online users except A and those users whohave blocked A. Inform. A that message could not be sent to some本团队核心人员组成主要包括BAT一线工程师,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全 汇编语言 硬件编程 软件设计 工程标准规等。其中代写编程、代写程序、代写留学生程序作业语言或工具包括但不限于以下范围:C/C++/C#代写Java代写IT代写Python代写辅导编程作业Matlab代写Haskell代写Processing代写Linux环境搭建Rust代写Data Structure Assginment 数据结构代写MIPS代写Machine Learning 作业 代写Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导Web开发、网站开发、网站作业ASP.NET网站开发Finance Insurace Statistics统计、回归、迭代Prolog代写Computer Computational method代做因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected] 微信:codehelp

你可能感兴趣的:(C代写 COMP9331 Computer Networks and Applications代写Java编程)