<0){gtk_text_buffer_get_end_iter(buffer,&iter);gtk_text_buffer_insert(buffer,&iter,"打开套接字时出错!n",-1);return FALSE;}s_in.sin_family=AF_INET;s_in.sin_port=htons(OUTPORT);s_in.sin_addr=*((struct in_addr *)host->h_addr);bzero(&(s_in.sin_zero),8);slen=sizeof(s_in);if(connect(sd,(struct sockaddr *) &s_in,slen)<0){gtk_text_buffer_get_end_iter(buffer,&iter);gtk_text_buffer_insert(buffer,&iter,"连接服务器时出错!n",-1);return FALSE;}else{gtk_text_buffer_get_end_iter(buffer,&iter);gtk_text_buffer_insert(buffer,&iter,username,-1);gtk_text_buffer_get_end_iter(buffer,&iter);gtk_text_buffer_insert(buffer,&iter,"n成功于服务器连接!n",-1);//write(sd,username,64);//isconnected=TRUE;return TRUE;}}void on_send(GtkButton *button,gpointer data){const char *message;if(isconnected==FALSE) return;message=gtk_entry_get_text(GTK_ENTRY(message_entry));sprintf(buf,"%sn",message);write(sd,buf,1024);gtk_entry_set_text(GTK_ENTRY(message_entry),"");}void on_login(GtkWidget *widget,GdkEvent *weent,gpointer data){creat_win();}void on_delete_event(GtkWidget *widget,GdkEvent *event,gpointer data){close(sd);gtk_main_quit();}int main(int argc,char *argv[]){GtkWidget *window;GtkWidget *vbox,*hbox,*button,*label,*view;if(!g_thread_supported())g_thread_init(NULL);gtk_init(&argc,&argv);window=gtk_window_new(GTK_WINDOW_TOPLEVEL);gtk_window_set_title(GTK_WINDOW(window),"客户端");g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(on_delete_event),NULL);gtk_container_set_border_width(GTK_CONTAINER(window),10);vbox=gtk_vbox_new(FALSE,0);gtk_container_add(GTK_CONTAINER(window),vbox);hbox=gtk_hbox_new(FALSE,0);gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,5);label=gtk_label_new("点击登录按钮连接服务器");gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,5);login_button=gtk_button_new_with_label("登录");gtk_box_pack_start(GTK_BOX(hbox),login_button,FALSE,FALSE,5);g_signal_connect(G_OBJECT(login_button),"clicked",G_CALLBACK(on_login),NULL);view=gtk_scrolled_window_new(NULL,NULL);gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(view),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);text=gtk_text_view_new();gtk_box_pack_start(GTK_BOX(vbox),view,TRUE,TRUE,5);gtk_container_add(GTK_CONTAINER(view),text);buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));hbox=gtk_hbox_new(FALSE,0);gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,5);label=gtk_label_new("输入:");gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,FALSE,5);message_entry=gtk_entry_new();gtk_box_pack_start(GTK_BOX(hbox),message_entry,FALSE,FALSE,5);button=gtk_button_new_with_label("发送");gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,FALSE,5);g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(on_send),NULL);gtk_widget_show_all(window);gdk_threads_enter();gtk_main();gdk_threads_leave();return FALSE;}
推荐阅读
- 查看Linux操作系统下的网络连接状态命令
- 在一个硬盘上安装两个Linux操作系统方法
- Windows Vista硬盘安装Fedora Linux系统
- 在Linux系统下使用wine运行迅雷5的方法
- Linux系统下Wine成功运行Bitcomet 1.01
- Linux操作系统JDK中文字体设置方法介绍
- 如何解决Linux操作系统下时间错误的问题
- 实用技巧:在Linux系统下享受IPv6的畅快
- Debian Linux系统Socks5服务器安装方法
- Linux操作系统终端下强大工具Screen使用