Fortran Coder

查看: 9911|回复: 3
打印 上一主题 下一主题

[求助] 初学者一枚,哪位大神能不能帮我看看···这个程序怎么改...

[复制链接]

23

帖子

10

主题

0

精华

熟手

F 币
145 元
贡献
90 点
跳转到指定楼层
楼主
发表于 2015-3-6 10:54:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
program server
         use KERNEL32
         use WS2_32

         implicit none
         integer WINSOCK_V2_2                        !版本
         integer connection_dropped_by_remote_party
         integer success
         parameter(WINSOCK_V2_2=X'202',connection_dropped_by_remote_party=X'05050505',success=0)
         type(T_SOCKADDR_IN) listenerInfo            !Server_add
         type(T_SOCKADDR_IN) connectionInfo          !client_add
         type(T_WSADATA) wsaInfo                     !版本信息结构

         type T_client_server_message
                union
                     map
                         integer receivelen        
                         integer sendlen      
                     end map
                     map
                       character*(100) receivebuffer
                       character*(100) sendbuffer
                     end map
                end union
         end type

         type(T_client_server_message)ClientServerMessage   
         integer connection        !socket_receive
         integer listener          !socket_server
         character*(15) host
         integer*2 port
         integer SendMsg            !send()
         integer ReceiveMsg         !recv()
         integer status

         ! Initialize Winsock v2.
         status=WSAStartup(WINSOCK_V2_2,wasInfo)
         if(status.NE.success)then
            write(*,*)'WSAStartup-',status
            stop
         end if

         ! 创建套接字
         listener=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)   
         if(listener.EQ.INVALID_SOCKET) then
             write(*,*)'socket-',INVALID_SOCKET

             status=WSACleanup()
             stop
         end if

         ! 设置连接地址
         host='0.0.0.0'
         port=55000

         listenerInfo%sin_family=AF_INET
         listenerInfo%sin_port=htons(port)
         listenerInfo%sin_addr%s_addr =inet_addr(host(1:LEN_TRIM(host)))

         ! 绑定套接字到某地的某个地址和端口
         status=bind(listener,%REF(listenerInfo),sizeof(listenerInfo))
         if(status.EQ.SOCKET_ERROR) then
            write(*,*)'bind -',WSAGetLastError()

            status = WSACleanup()
            stop
         end if

         !监听状态
         do while(.true.)
              status = listen(listener,1)
              if(status<0)then
                  write(*,*)'listen -'

                  status=WSACleanup()
                  stop
              end if
              !接受连接
              if (status.EQ.SUCCESS) then
                   connection=SOCKET_ERROR

                   do while(connection.EQ.SOCKET_ERROR)
                       connection=accept(listener,%REF(connectionInfo),0)

                       call sleep(100)
                    end do

                    !进行聊天

                    !接收数据
                    do while(.true.)
                        clientServerMessage%receivelen=recv(connection,clientServerMessage%receivebuffer,100,0)
                        if(clientServerMessage%receivelen<0)then
                           write(*,*)"接受失败,程序退出"
                           stop
                        else
                           write(*,*)"client say:",clientServerMessage%receivebuffer
                         end if
                       !发送数据
                          write(*,*)"please enter message:"
                          read(*,*) clientServerMessage%sendbuffer
                          clientServerMessage%sendlen=send(connection,clientServerMessage%sendbuffer,100,0)
                          if(clientServerMessage%sendlen<0)then
                            write(*,*)"发送失败"
                          end if

                     end do
                  end if
             end do

             status =closesocket(connection)
             status =closesocket(listener)
             status =WSACleanup()

             pause

        stop
        end




错误        26        Compilation Aborted (code 1)        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        1       
警告        19         warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL.   [LEN_TRIM]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        58       
错误        18         error #6514: A substring must be of type CHARACTER.   [HOST]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        58       
错误        25         error #6460: This is not a field name that is defined in the encompassing structure.   [SENDLEN]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        102       
错误        24         error #6460: This is not a field name that is defined in the encompassing structure.   [SENDBUFFER]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        101       
错误        22         error #6460: This is not a field name that is defined in the encompassing structure.   [RECEIVELEN]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        92       
错误        23         error #6460: This is not a field name that is defined in the encompassing structure.   [RECEIVEBUFFER]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        92       
错误        14         error #6404: This name does not have a type, and must have an explicit type.   [WASINFO]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        37       
错误        13         error #6404: This name does not have a type, and must have an explicit type.   [STATUS]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        37       
错误        17         error #6404: This name does not have a type, and must have an explicit type.   [PORT]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        54       
错误        15         error #6404: This name does not have a type, and must have an explicit type.   [LISTENER]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        44       
错误        20         error #6404: This name does not have a type, and must have an explicit type.   [LEN_TRIM]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        58       
错误        16         error #6404: This name does not have a type, and must have an explicit type.   [HOST]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        53       
错误        21         error #6404: This name does not have a type, and must have an explicit type.   [CONNECTION]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        80       
错误        12         error #6404: This name does not have a type, and must have an explicit type.   [CLIENTSERVERMESSAGE]        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        27       
错误        4         error #6386: Confused statement; this is neither a valid I/O TYPE stmt, nor a valid F90 derived-type-stmt, nor a valid F90 type-declaration-stmt.        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        27       
错误        5         error #6236: A specification statement cannot appear in the executable section.        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        28       
错误        6         error #6236: A specification statement cannot appear in the executable section.        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        29       
错误        7         error #6236: A specification statement cannot appear in the executable section.        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        30       
错误        8         error #6236: A specification statement cannot appear in the executable section.        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        31       
错误        9         error #6236: A specification statement cannot appear in the executable section.        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        32       
错误        10         error #6236: A specification statement cannot appear in the executable section.        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        33       
错误        11         error #6236: A specification statement cannot appear in the executable section.        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        34       
错误        3         error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( * ) . % + - [ . ** / //        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        27       
错误        1         error #5078: Unrecognized token 'T_client_server_message?' skipped        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        27       
错误        2         error #5078: Unrecognized token '?' skipped        d:\documents\visual studio 2010\Projects\Console9\Console9\Source1.f90        27       


分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

23

帖子

10

主题

0

精华

熟手

F 币
145 元
贡献
90 点
沙发
 楼主| 发表于 2015-3-6 13:42:23 | 只看该作者
自己改的已经显示没有错误了,谢谢大家···

100

帖子

0

主题

0

精华

专家

F 币
550 元
贡献
291 点

规矩勋章元老勋章

QQ
板凳
发表于 2015-3-7 17:13:03 | 只看该作者
socket编程.高端啊

23

帖子

10

主题

0

精华

熟手

F 币
145 元
贡献
90 点
地板
 楼主| 发表于 2015-3-13 12:52:07 | 只看该作者
初学教授就让搞这个···教授太折磨我了···
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-16 03:41

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表